What is the Regular Expression for DD-MM-YYYY date format in XML regex? -


this question has answer here:

i want know regex date dd-mm-yyyy format. , rule

the ·day· value must no more 30 if ·month· 1 of 4, 6, 9, or 11, no more 28 if ·month· 2 , ·year· not divisible 4, or divisible 100 not 400, , no more 29 if ·month· 2 , ·year· divisible 400, or 4 not 100.

i wanted in xml regex in xsd.

accept-- 29-02-2000, 31-05-2013, 30-04-2012

reject-- 29-02-1900, 31-04-2013, 30-02-2000

i had regex lying around, made while competition friend of mine!

the following friend's, , 20% faster:

^(?!00)((([0-2]\d|3[01])-(0[13578]|1[02])|([0-2]\d|30)-(0[469]|11)|([01]\d|2[0-8])-02)-\d{4}|([01]\d|2\d)-02-(([02468][048]|[13579][26])(?=00)|\d{2}(?!00))([02468][048]|[13579][26]))$ 

while 1 shortest (fits on twitter, challenge):

^(?!(00|30-02))(((?=.+(?!00)([02468](?=[048](00)?$)|[13579](?=[26](00)?$)))|(?!29-02))[012]\d|30|31(?!-(0[2469]|11)))-(0[1-9]|1[012])-\d{4}$ 

note both regexes fail validate yyyy = 0000, it's not valid year, according gregorian calendar.

both regexes free of lookbehinds , conditionals, had work in javascript.

edit:

since need xml, i've modified first regex bit, needed slight modification rid of lookaround.

((0[1-9]|[1-2]\d|3[01])-(0[13578]|1[02])|([0-2]\d|30)-(0[469]|11)|(0[1-9]|1\d|2[0-8])-02)-\d{4}|(0[1-9]|[12]\d)-02-(([02468][048]|[13579][26])00|(\d{2}([02468][48]|[2468][048]|[13579][26]))) 

i hope works you.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -