正則指引-量詞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, @"^.+$");//.匹配任意字符string

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

相關文章
相關標籤/搜索