in reply to Re^2: Bug with finding all regexp matches
in thread Bug with finding all regexp matches

To add to the previous post: For
perl -e 'use re "debug"; "01234" =~ /^(.+?)(.+)((?:.z?)+)$(?{ print "$ +1 $2 $3\n" })(*FAIL)/' 2>&1 | less
two results are missing and there are two entries
whilem: (cache) already tried at this position... failed...
It figures.

Replies are listed 'Best First'.
Re^4: Bug with finding all regexp matches
by Anonymous Monk on Oct 15, 2016 at 19:07 UTC
    I opened a bug on this, https://rt.perl.org/Ticket/Display.html?id=129886 .
      This isn't a bug, it's intended behaviour :-). The superlinear cache kicks in for various types of complex/nested quantifiers (such as (z?)+) to avoid heat-death-of-the-universe time to find failure. It records pattern/string position combos where a match failed, and if it comes across the same combo again it stops and backtracks immediately at that point rather than continuing with the rest of the pattern (which will inevitably fail later).

      See the very first paragraph in perlre.pod about re_evals:

      B<WARNING>: Using this feature safely requires that you understand its limitations. Code executed that has side effects may not perform identically from version to version due to the effect of future optimisations in the regex engine. For more information on this, see L</Embedded Code Execution Frequency>
      Where that link goes to: Embedded Code Execution Frequency

      Dave.

        This isn't a bug, it's intended behaviour :-)

        Hmm, I see your point but AFAIU (*FAIL) itself doesn't add to regexp complexity and could be exempted from caching to allow (${ eval })(*FAIL) pattern to work as the doc itself suggests in other place. Still, my bug report landed next to others that are 4 years old, and given your comment I see where it will go...

        So, is there a way in Perl to find all regexp matches?