in reply to Regex code block executes twice per match using look-arounds
I've also been trying to interprete the output from use re 'debug';, but the message "Match possible, but length=0 is smaller than requested=1, failing!" has me stumped.
But I did find a workaround for the problem. Adding a non-greedy 0 or 1 quantifier to the code assertion prevents it from being executed twice:
my $rxBetween = qr/ (?<= []>})] ) (?= [[<{(] ) (?{ print "'$`'$&'$''" })?? /x;
This simplified (to reduce the trace output) version of your regex now produces
C:\test>junk6 2>junk6.trace Before: (x1)[x2]{x3}(x4) ---------------------------------------- '(x1)''[x2]{x3}(x4)' '(x1)[x2]''{x3}(x4)' '(x1)[x2]{x3}''(x4)' ---------------------------------------- After: (x1)+[x2]+{x3}+(x4)
I've had a go at coming up with an explanation ,from looking at the way it changes the debug trace...but I decided that I am well up on my mental torture quota for this month, so I'll let someone else have that pleasure :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex code block executes twice per match using look-arounds
by johngg (Canon) on Jul 12, 2007 at 22:07 UTC | |
by BrowserUk (Patriarch) on Jul 12, 2007 at 22:17 UTC |