Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
RE: Re: ^x* vs x*$by tye (Sage) |
on Aug 19, 2000 at 22:02 UTC ( [id://28655]=note: print w/replies, xml ) | Need Help?? |
When this second item has come up before, it has been defended as being the correct behavior. The more general case is that when a regex can match a zero-width string, it is possible for multiple matches to end at the same point. Another example is:
which produces
This is because we start at position 0 and match "a", leaving us a position 1. At position 1 we match "", leaving us at position 2 (we've already started at position 1 so we don't start there again, even though our match ended at position 1). At pos 2 we match "a", at pos 3 we match "", etc. But this is a bit counter intuative. In fact, sed doesn't have this "quirk". So it might be a good idea to disallow zero-width matches that start (and therefore end) at the point where the previous match ended. But that raises the ugly spectre of backward compatability... My current feeling is that "we" should "fix" this but provide a way to get the old behavior to ease the burdon of backward compatability (though no suitable syntax/feature for doing that springs to mind). I suspect a lack of to-its will cause the current behavior to remain until someone feels strong enough about it to champion its cause. - tye (but my friends call me "Tye")
In Section
Seekers of Perl Wisdom
|
|