2015-10-07 27 views

回答

1

這真的很容易使一個正則表達式匹配得:

 string[] input = new string[6] 
     { 
      "[email protected]", // match 
      "[email protected]", // match 
      "[email protected]", // match 
      "[email protected]", // not a match 
      "[email protected]", // not a match 
      "[email protected]" // not a match 
     }; 

     string pattern = @"Auto_gen_\d{4}@mail.com"; //\d{4} means 4 digits 
     foreach (string s in input) 
     { 
      if (Regex.IsMatch(s, pattern)) 
      { 
       Console.WriteLine(string.Format("Input {0} is valid",s)); 
      } 
      else { 
       Console.WriteLine (string.Format("Input {0} is not valid",s)); 
      } 
     } 
     Console.ReadKey(); 
相關問題