stumped on a reg expression
Date: 06/01/06
(PHP Community) Keywords: no keywords
I try to get out of them when I can (will go out of the way to use explode when I can). But in this instance, I can't. And I'm stumped on one character
Here's the format
any string with spaces:numeric/numeric ("john doe:45/89" for instance)
here's my expression:
preg_match('/[[:alnum:] ]:[0-9]\/[0-9]/', "john doe:45/89")
I can get everything to match up until I throw the / into the expression. I thought a \ would recognize it as a character. The numbers (or string before :) can be of any size. Can anyone with more experience with regular expressions tell me what I'm missing?
I THINK I FOUND IT
preg_match('/^[a-zA-Z0-9 ]+:[0-9]+\/[0-9]+$/', "john doe:45/89")
I think pcre can get confused with POSIX shorthand like [:alnum:] especially if you're mixing in other characters (I think that even happens with ereg(). I broke it down old school way, put my +'s in (thanks signe), threw a $ at the end (found a hole there). I did multiple tests and I THINK it's pretty solid now. If anyone sees a hole in the format now, correct me (please :).
Source: http://community.livejournal.com/php/455537.html