Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Problem with regex

  • 09-03-2008 04:38PM
    #1
    Registered Users, Registered Users 2 Posts: 7,041 ✭✭✭


    I have this regex (preg_match) but it won't work and I'm not sure why

    [PHP]
    $regex="/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)-([1-9]{1}|[1-2]{1}[0-9]{1}|[3]{1}[0-1]{1})/([1-9]{1}|[1]{1}[0-2]{1})/'20'([0-9]{2})$/";
    if(preg_match($regex, $input)){ //<<Line 560
    [/PHP]

    It should accept strings like Tuesday-5/5/2005 but I get the error

    Warning: preg_match() [function.preg-match]: Unknown modifier '(' in D: path/to/file.php on line 560

    Any Help?


Comments

  • Registered Users, Registered Users 2 Posts: 1,346 ✭✭✭carveone


    Seachmall wrote: »
    I have this regex (preg_match) but it won't work and I'm not sure why

    Humph. Boards.ie smoked my reply - let's try again!

    I believe that the - and / characters after "Sunday)" and before "'20'" respectively should be escaped - ie: "\-" and "\/". Also not sure why you've quoted the '20', probably shouldn't!

    Conor.

    PS: "[1-9]{1}" and "[1-9]" are the same thing except the latter is less cluttered.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Check out ReguLazy


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Nice app called RegExBuddy will help you no end with that.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Regex Builder is free and handy if you're on windows.


Advertisement