in reply to Re^3: zero-length match increments pos() (two!)
in thread zero-length match increments pos()
If \w?? matches an empty string rather than "a" (because it prefers the shorter match, it being anti-greedy), then I don't expect it to go on to match "a" next; it already made its decision regarding "a" and should move on to the next decision point.
What is 'it' in this context? Im assuming you mean the quantifier ??, in which case ill say that A? is syntactic sugar for (?:A|) and A?? is for (?:|A) and in 5.10 we will have A?+ which will be the same as (?>A|). Note all three are different, and have a choice point before consuming the 'A' part of the pattern (the entry into the alternation).
I will admit that the optimiser should be clever enough to turn /A?B/ and /A??B/ into /A?+B/ when A does not match B. But I dont think it makes sense to talk about A?? not matching the empty string first when A can match B, after all you dont wan't 'a'=~/a??a/ to fail because the first a matched (if you wanted that you should have written a?a). Having subtleties like this does allow one to make some mistakes but it also alows the user to hand tailor how the match proceeds.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: zero-length match increments pos() (anti-greedy)
by tye (Sage) on Nov 09, 2006 at 03:48 UTC | |
by demerphq (Chancellor) on Nov 09, 2006 at 10:59 UTC |