PHP regex optional non-matching groups? -


i'm trying make date regex allows years 1900 2099, 19 or 20 optional.

i'm there, can't find way allow 19 or 20 optional part. here's i've got:

(?:20)(?:19)?[0-9][0-9] 

testing results:

string    preg_match     ok?  ======    ==========     =========== 55         yes             yes 1955       yes             yes 2055       yes             yes 201955     yes             no 

can out?

this it:

^(?:19|20)?\d{2}$ 

it says:

^ = start of string

(?:19|20)? = match 19 or 20 without capturing, 0 or 1 times

\d{2} = 2 decimal digits

$ = end of string


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -