Re: preg weirdness?

From: Date: Fri, 28 May 1999 22:15:52 +0000
Subject: Re: preg weirdness?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-6208@lists.php.net to get a copy of this message
Rasmus Lerdorf wrote: > 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. Ok, go ahead and test it now. I figured out a way to to fix this, but it involved modifying the actual PCRE library a bit. But now, the tests you did should work perfectly. I tested the same ones in Perl and they match with what preg_replace does. What this means though is that people won't be able to link against new versions of PCRE unless we update the bundled one. It shouldn't be a big deal to do it every time new PCRE comes out, but just in case, I emailed the author and asked him to consider putting the changes I made into the PCRE. -Andrey * Anything will fit if you push hard enough * -- 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

« previous php.dev (#6208) next »