正则指引-量词demo

class Program
{
static void Main(string[] args)
{
string str = "1\"3";
var re1 = Regex.IsMatch(str, @"^\d\d\d\d\d\d$");//数字出现6次
var re2 = Regex.IsMatch(str, @"^\d{6}$");//使用量词
var re3 = Regex.IsMatch(str, @"^\d{6,10}$");//使用量词范围
var re4 = Regex.IsMatch(str, @"^\d{6,}$");//使用量词范围,无上限
//常用量词:*+?
var re5 = Regex.IsMatch(str, @"^travell?er$");//?:不出现或出现一次
var re6 = Regex.IsMatch(str, @"^100.3*$");//*:不出现或出现
var re7 = Regex.IsMatch(str, @"^100.3+$");//+:至少出现一次
var re8 = Regex.IsMatch(str, @"^.+$");//.匹配任意字符

Console.WriteLine(re8);
Console.ReadKey();
}
}

posted @ 2013-09-24 18:39  八神吻你  阅读(392)  评论(0编辑  收藏  举报