Checking Birthday By Regular Expression

Introduction
 
The example tries to match birthdays to a regular expression. For demonstration purposes, the expression matches only birthdays that do not occur in April and that belong to people whose names begin with "k".

  1. // create regular expression                 
  2. Regex expression = new Regex(@"K.*\d[0-35-9]-\d\d-\d\d");  
  3. string string1 = "Kanhu's Birthday is 05-12-75\n" + "Panchanan's Birthday is 11-04-68\n" + "Suraj's Birthday is 04-28-73\n" +"Kailash's Birthday is 12-17-77";  
  4. // match regular expression to string and  
  5. // print out all matches  
  6. foreach (Match myMatch in expression.Matches(string1))  
  7. Console.WriteLine(myMatch);  
  8. Console.ReadLine();

Output

c# regular expression