in reply to Re: Regex code block executes twice per match using look-arounds
in thread Regex code block executes twice per match using look-arounds

Thank you for your reply. I would never have thought of trying that. I didn't even realise you could use a quantifier on a code block. Doing that along with re debug shows that the code block doesn't execute at the first and successful match but at the second retried match when the engine realises that, although successful, it has already been here before. I wonder why the non-greediness doesn't hold the second time around.

Exploring quantifiers with code blocks could be very interesting.

$ perl -le ' > $str = q{abc}; > $str =~ m{(b)(?{print qq{Match $1}}){3}};' Match b Match b Match b $

Thanks again,

JohnGG

  • Comment on Re^2: Regex code block executes twice per match using look-arounds
  • Download Code

Replies are listed 'Best First'.
Re^3: Regex code block executes twice per match using look-arounds
by BrowserUk (Patriarch) on Jul 12, 2007 at 22:17 UTC
    I would never have thought of trying that.

    You'll note that I carefully omitted any description of the tortured, and almost certainly erroneous, logic that led me to try such a thing in the first place.

    Since 'discovering' the idea of quantifiers on zero-length assertions, I've been trying to think of a good use for it. Other than simulating a stutter, I haven't thought of anything useful yet :)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.