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".


// create regular expression               

            Regex expression = new Regex(@"K.*\d[0-35-9]-\d\d-\d\d");

            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";

            // match regular expression to string and

            // print out all matches

            foreach (Match myMatch in expression.Matches(string1))

                Console.WriteLine(myMatch);

            Console.ReadLine();


Output

CheckingBirthday.JPG


Ebook Download
View all
Learn
View all