in reply to Leaking Regex Captures

use re 'debug';

Replies are listed 'Best First'.
Re^2: Leaking Regex Captures
by SuicideJunkie (Vicar) on Aug 05, 2009 at 12:43 UTC
    That's quite handy, and thanks for posting it, but sadly it does not explain why the marked branch sets the value of $1 to 'g' even though it "failed..." to match:
    3 <ebf> <g> | 3: BRANCH(11) 3 <ebf> <g> | 4: OPEN1(6) 3 <ebf> <g> | 6: REG_ANY(7) 4 <ebfg> <> | 7: CLOSE1(9) 4 <ebfg> <> | 9: EXACTF <b>(14) failed... 3 <ebf> <g> | 11: BRANCH(13)

      That's quite handy, and thanks for posting it, but sadly it does not explain why the marked branch sets the value of $1 to 'g' even though it "failed..." to match:

      Match successful! means it NOT fail.

        The overall regex matches. But the branch doing the capturing fails when the 'g' is in that position. The capture branch is only successful the first time, when it matches 'eb' and should capture the 'e'. Then the next times around it fails, but still captures.

        The inconsistent capturing when backtracking in alternations inside repetitions are involved. That is what does not make sense, and what I am trying to understand.