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
Post a Comment