Re: Negative Look Ahead Regex - Code Mistake or Bug?
| From: | Ashley Sheridan | Date: | Sun, 17 Aug 2008 23:41:11 +0000 |
| Subject: | Re: Negative Look Ahead Regex - Code Mistake or Bug? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278257@lists.php.net to get a copy of this message | ||
Hi Cameron,
As far as I can tell, you have an error in your syntax. You're using a -
(hyphen) character in the first match, but Regex uses this to define a
range of characters. It seems that if you don't escape it, the whole
thing behaves a little strangely. For example, using your URL as the
source string:
http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
This regular expression
/^(http:\/\/www\.domain\.com([\/\.\-\_\w]*))/
matches
[!MATCH!]?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
and this
/^(http:\/\/www\.domain\.com([\/\.-\_\w]*))/
matches the whole URL
The only difference is the hyphen has been escaped in the first
expression.
I'm not sure if this will help any, but it's definitely something I
noticed in the regex.
Ash
www.ashleysheridan.co.uk