Forum Moderators: coopster

Message Too Old, No Replies

Again regular expressions...

using colons

         

lars stecken

6:41 pm on Apr 29, 2003 (gmt 0)

10+ Year Member



Hi everybody,

after checking many books and internet resources I give up.

I found this regular expression to check a date on www.regexlib.com and I can't get it to work in PHP:

<mod note>
the following 4 lines should be all on one, sorry tough edit and a ton of side scroll : jatar_k
</mod note>

^(?:(?:31(\/¦-¦\.)(?:0?[13578]¦1[02]))\1¦(?:(?:29¦30)(\/¦-¦\.)
(?:0?[1,3-9]¦1[0-2])\2))(?:(?:1[6-9]¦[2-9]\d)?\d{2})$¦^(?:29(\/¦-¦\.)0?2\3
(?:(?:(?:1[6-9]¦[2-9]\d)?(?:0[48]¦[2468][048]¦[13579][26])¦(?:(?:16¦[2468][048]¦[3579][26])00))))
$¦^(?:0?[1-9]¦1\d¦2[0-8])(\/¦-¦\.)(?:(?:0?[1-9])¦(?:1[0-2]))\4(?:(?:1[6-9]¦[2-9]\d)?\d{2})$

(This expression should basically match any German style date like 29.04.1600, also providing a check on leap years)

I assume it is a synthax problem but I am not sure. Also, I have no clue what the sythax "?:" is supposed to mean.

Can anybody help?

Thanks a bunch,
Lars

[edited by: jatar_k at 5:17 am (utc) on April 30, 2003]

ShawnR

12:03 am on Apr 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"(?:pattern)" is the same as grouping (i.e. as in "(pattern)", except that it does not populate $1, $2, etc.

It is a pretty complex regex... It knows how many days are in each month, and checks for leap years, etc. Can you post your php code (pregmatch call) as well, and disable gaphic faces.

Shawn

DrDoc

12:58 am on Apr 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



use checkdate() [php.net] instead ;)