preg weirdness?
| From: | Rasmus Lerdorf | Date: | Fri, 28 May 1999 04:03:20 +0000 |
| Subject: | preg weirdness? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6108@lists.php.net to get a copy of this message | ||
Ok, just to test out the pcre stuff I did a couple of tests:
$a="abc";
echo preg_replace("/.*/","X",$a);
Here are the results, replacing the regex argument each time:
regex expected got
/.*/ X XX <==
/.+/ X X
// <error> XaXbXcX <==
/\w/ XXX XXX
/^\w+$/ X X
/\b/ XabcX XaXbXc <==
/^\w*?/ Xabc Xabc
/^\w+?/ Xbc Xbc
The first one just looks wrong to me. But the behaviour is the same in
ereg_replace, so I guess it is correct.
I suppose the second surprising one can be explained. It is just sort of
funny to think about though. There is exactly 1 nothing before and after
every char in the string? Here preg_replace() differs from
ereg_replace(). ereg_replace() will throw an error.
And the third weird one looks like a bug to me. \b is supposed to be a
word boundary. That is, it should match the transition from a \W to a \w
and vice versa. I only see two word boundaries like that in the "abc"
string. The actual output makes no sense unless the pcre library doesn't
understand \b being a word boundary.
-Rasmus
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net