C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Checking Birthday By Regular Expression
WhatsApp
Kailash Chandra Behera
6y
14.6
k
0
2
25
Blog
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
People also reading
Membership not found