Title |
Test
Find
Pattern Title
|
Expression |
(?<Year>(19|20)[0-9][0-9])-(?<Month>0[1-9]|1[0-2])-(?<Day>0[1-9]|[12][0-9]|3[01]) |
Description |
This pattern will match all dates from the year 1900 to 2099, invalid dates like 0000-00-00 will not be accepted.
Replacement string can be used as the Year Month and day is named.
The "-" character can be replaced with "/" character for the required format, and also the <Year>, <Month> and <Day> can also be interchanged according the local culture format (eg dd/mm/yy) |
Matches |
1900-01-01 | 2099-12-31 | 2004-10-11 |
Non-Matches |
2004-01-00 | 2004-00-01 | 0000-01-01 |
Author |
Rating:
Binoj Antony
|
Source |
|
Your Rating |
|
Title: Of course there are better reg ex out there
Name: Binoj Antony
Date: 10/15/2004 7:15:23 AM
Comment:
Hey there are of course leap years and 30/31 month-end day problems in this reg ex that I posted, but the idea was to have a simple and small reg ex, you will also see that this reg ex is very easy to understand....
With the same output can you make this reg ex shorter??
Title: Question
Name: Szoke
Date: 10/11/2004 10:12:44 AM
Comment:
What about different number of days in different months? And about leap year? Try this:
^((([1-9]|[12]\d|3[01])\/([13578]|1[02])\/((1[6-9]|[2-9]\d)\d{{2}}))|(([1-9]|[12]\d|30)\/([13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{{2}}))|(([1-9]|1\d|2[0-8])\/2\/((1[6-9]|[2-9]\d)\d{{2}}))|(29\/2\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$