|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-09-25 14:41 UTC] john at scl dot co dot uk
These 2 are OK:
ereg_replace('..','b','aa') -> b
ereg_replace('.+','b','aa') -> b
But this is wrong:
ereg_replace('.*','b','aa') -> bb
You can "fix" it by binding to the beginning:
ereg_replace('^.*','b','aa') -> b
but not by binding to the end:
ereg_replace('.*$','b','aa') -> bb
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
Derick! This _is_ a bug! I've now upgraded to 4.2.1 and the behaviour remains the same. Consider just these two: ereg_replace('.+','b','aa') -> b ereg_replace('.*','b','aa') -> bb and this from man 7 regex: "An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom." How can it NOT be a bug?AFAIK, POSIX re's have no concept of non-greedy quantifiers. All quantifiers are greedy. But even supposing that this were a possibility i.e. the * quntifier is non-greedy, the following needs explaining: 1) Why the difference between + and * ? 2) ereg_replace('.*','b','aa') should produce an _infinite_ string of b's because the minimum match is the empty string and the global ('g' modified) behavior means that there are an infinity of minimum matches available. 3) ereg_replace('.*c','b','aac') should produce 'ab' but it doesn't, it produces just 'b'. In other words, the addition of the 'c' following the * quantifier has changed the behaviour from non-greedy to greedy! There is no consistent explanation available for this behaviour. The behaviour is just plain wrong!