I am wondering why "backtrack" doesn't behave the way originally expected and why the edited version works? Thank you!The output of the following line of code is different than what is des +cribed in the text: "abcdef" =~ / .+ (?{say "Matched so far: $&"}) bcdef $/x; The text states that this prints the following: Matched so far: abcdef Matched so far: abcde Matched so far: abcd Matched so far: abc Matched so far: ab Matched so far: a But I am finding that only the last line gets printed: Matched so far: a One solution to get the output that the text describes is to slightly +modify the code example to the following: "abcdef" =~ / .+ (?{say "Matched so far: $&"}) .cdef $/x;
In reply to Interesting behavior of regular expression engine by lightoverhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |