Log in

View Full Version : Resolved Pattern Invalidated by Ending $ Anchor



Jesdisciple
06-07-2009, 03:03 AM
EDIT: Hmm, maybe I've lost my sense of sufficient testing during my hiatus... The / (slash) in the regex represents a variable substition, the value of which is the first character in another variable. The other variable contains an empty string. Lesson learned: Specific requirements are very good debugging tools.

Grr... It works there (http://www.solmetra.com/scripts/regex/index.php) but not on my localhost (PHP v5.2.6-3ubuntu4.1). It's supposed to match *nix paths, and it actually works without the ending $. But I want to specify that the whole string should be matched, because you never know when a freak case will blow your assumption to pieces.

The pattern:
{^[.a-z0-9_\-]*(/[.a-z0-9_\-]*)+$}i

Test cases:
/lib
/var/www (only used on the above site because a design decision makes my script not use it anymore)


The test cases contain nothing after the printable characters. Why in the world does that dollar sign matter so much? I'm also curious why my server cares but theirs doesn't, but you probably can't answer that.

Thanks.