Mark S. wrote:
>
> Here's a probably inefficient date VALIDATOR for dates starting 0000-01-01
>> following format yyyy-mm-dd (which I find to be the most generally
>> useful). Ok, I didn't check the rules. I think there's something about a
>> surprise
>>
> leap year every 400 years, so there's probably more tweaking to be done to
> match the Gregorian calendar precisely.
>
> <option
> value="^(?=\d{4})(((?!\d\d(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96))\d{4}-(((0[13578]|10|12)-(0[1-9]|[12]\d|30|31))|((04|06|09|11)-(0[1-9]|[12]\d|30))|((02)-(0[1-9]|1\d|2[1-8]))))|((?=\d\d(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96))\d{4}-(((0[13578]|10|12)-(0[1-9]|[12]\d|30|31))|((04|06|09|11)-(0[1-9]|[12]\d|30))|((02)-(0[1-9]|1\d|2[1-9])))))">Experimental
>
> VALIDATE yyyy-mm-dd</option>
>
>
Lol! Nice one! I'd put that in the REALLY ADVANCED category for regex!
Most users would have no clue how that works!
Anyway I think you got it off the net? It's not bad, but faulty :-).
Practically speaking matching dates with specific calendars from 0001 is
prone to error. This is nothing to do with regex or computers. Its that the
transitions between the Julian and Gregorian calendar meant (for English
speaking countries) 10 days were lost from history. So really you need more
than one regex to cover Julian & Gregorian, and it will vary between
country (Catholic countries adopted Gregorian dates first and about 7 days
were destroyed).
Here is a regex for Gregorian dates that matches (century) leap years
accurately.
Match Gregorian dates 1800 -> 9999
<option value="^
*((?:(?:1[8-9]|[2-9]\d)\d{2}([-/.]))(?:(?:(?:0[13578]|1[02])\2(?:0[1-9]|[12][0-9]|3[01]))|(?:(?:0[469]|11)\2(?:0[1-9]|[12][0-9]|30))|(?:(?:02)\2(?:0[1-9]|1[1-9]|2[1-8])))|(?:(?:1[8-9]|[2-9]\d(?:04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)([-/.])(?:02)\3(?:29))|(?:(?:[2468][048]|[3579][26])(?:00)([-/.])(?:02)\4(?:29)))$*>Match
dates 1800-9999 in "yyyy[-/.]mm[-/.]dd" format</option>
The *"**([-/.])" *means the data separator can be *"-"*, *"."* or *"/"*.
*"(?: ...)"* starting *"?:"* means "use this capturing group, but don't
retain it". It makes complex regular expressions easier to work with.
Note: the regex needs to be *one line,* not broken by line-breaks as google
does.
The regex could have utility in some cases (for historians?,
calanderians?), but I think they would be rare??
But its good example that regex can sometimes be quite clever.
TT
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/3d6b9e45-fe42-4616-b2b6-3f71562678a7%40googlegroups.com.