Reputation: 1433
Weird things happened when a website I am working on got moved to another server with newer version of PHP. The regex that was working normally on 3 other different servers refuses to work, returns 0 all the time.
This is the original regex:
/\A(?P<text>[[:alpha:]]{4})[[:space:]](?P<password>[\p{L}\p{N}]{3,})[[:space:]](?P<digit1>[[:digit:]]{2,4})[[:space:]](?P<digit2>[[:digit:]]{1,2})\z/u
password had to be unicode, before it was just [[:alnum:]] but there were some problems with clients.
And these are the ones I tried to no avail:
/\A(?<text>[[:alpha:]]{4}) (?<password>[[:alnum:]]{3,}) (?<digit1>[[:digit:]]{2,4}) (?<digit2>[[:digit:]]{1,2})\z/u
/\A(?<text>[\p{L}]{4}) (?<password>[\p{L}\p{N}]{3,}) (?<digit1>\d{2,4}) (?<digit2>\d{1,2})\z/u
Example text: ABCD 1a2b3c 100 50
All of these were tested on http://www.spaweditor.com/scripts/regex/index.php and worked perfectly.
Can anyone tell me what's wrong with it? I know it might not be the prettiest regex you've seen but it works (or at least worked until now) just like expected. Right now I'm blaming the PHP (lol).
Edit: tested the last pattern on these sites:
* http://regex.larsolavtorvik.com/
* http://www.spaweditor.com/scripts/regex/index.php
* http://www.pagecolumn.com/tool/pregtest.htm
* http://lumadis.be/regex/test_regex.php
and on some others where it allowed to type my regex fully myself, with slashes and u
flag.
In all of these websites it worked, but on some others I checked it didn't, same as my server.
PCRE is unicode-enabled...
Edit: seems that sysadmins changed something after all... didn't work until 10 minutes earlier :/ Somebody close this question, all of the regexes now work.
Upvotes: 3
Views: 177