日期:2014-05-17 浏览次数:20930 次
str1="xxxxxxxxxxcsdnnetxxxxxxxxxxxxxx"; str2="xxxxxxccdnnetxxxxxxxx"; str3="xxxxxxxxxxxxxxxxcsdnnatxxxxx"; str4="xxxxxxxxcssnnatxxxxxxxxxxxxxxxx";
tmpstr="csdnnet";
void Main() { string str1="xxxxxxxxxxcsdnnetxxxxxxxxxxxxxx"; string str2="xxxxxxccdnnetxxxxxxxx"; string str3="xxxxxxxxxxxxxxxxcsdnnatxxxxx"; string str4="xxxxxxxxcssnnatxxxxxxxxxxxxxxxx"; Console.WriteLine("{0}:\t{1}",str1,CheckString(str1)); Console.WriteLine("{0}:\t{1}",str2,CheckString(str2)); Console.WriteLine("{0}:\t{1}",str3,CheckString(str3)); Console.WriteLine("{0}:\t{1}",str4,CheckString(str4)); /* xxxxxxxxxxcsdnnetxxxxxxxxxxxxxx: OK xxxxxxccdnnetxxxxxxxx: OK xxxxxxxxxxxxxxxxcsdnnatxxxxx: OK xxxxxxxxcssnnatxxxxxxxxxxxxxxxx: ERROR */ } string[] temp=new string[]{"csdnnet","[a-z]sdnnet","c[a-z]dnnet","cs[a-z]nnet" ,"csd[a-z]net","csdn[a-z]et","csdnn[a-z]t","csdnne[a-z]"}; string CheckString(string str) { string result="ERROR"; Regex reg; foreach(string s in temp) { reg=new Regex(s); if(reg.IsMatch(str)) { result="OK"; break; } } return result; }