string pattern = "^\\d{2}$";

解决方案 »

  1.   

    string pattern = "^\\d{2}$";
    输入22第一次匹配,第二次就不匹配了,而且还匹配333长度三位的,怎么还是和MSDN不一样?高手请一试!
      

  2.   

    impossiblestring[] slist  = {"11","222","1a","333","444"};
    Regex rg = new Regex(@"^\d{2}$");
    foreach (string s in slist)
      Console.WriteLine("{0}:{1}", s, rg.IsMatch(s));
    output:
    11:True
    222:False
    1a:False
    333:False
    444:False
      

  3.   

    Thank you very much,Expert!My problem at:
    string str = Console.ReadLine();
    Extension(str);
    Console.Read(); //Only read in one character!!!