in reply to zero-length match increments pos()
Note that it would be even better if the regex engine, instead of just enforcing that two matches can't start at the same offset, would also enforce that two matches can't end at the same offset. For example:
$str= "bbbcccbbb" while( $str =~ /b*/g ) { print "($`)<$&>($')\n" } __END__ ()<bbb>(cccbbb) (bbb)<>(cccbbb) <-- This one (bbbc)<>(ccbbb) (bbbcc)<>(cbbb) (bbbccc)<bbb>() (bbbcccbbb)<>() <-- This one
The two indicated matches should be skipped since they end at the same offset as the matches that preceed them. Note that most non-Perl regex processors know that this makes sense. For example, sed doesn't make this mistake. In vi:
a bbbcccbbb . s/(b*)/x\1/g
produces
xbbbcxcxcxbbb /\ /\ no "x"s there
as is sensible.
A minor surprise but something worth fixing when not shackled by backward compatability (ie. this deserves to be fixed in Perl6).
- tye
|
|---|