perlquestion
jimav
<p>I want to use a regex to match double-quoted strings of arbitrary length.
But the regex recommended in perlre(1) seems to use recursion even though greedy *+ is used, which that
man page seems to say should prevent backtracking.</p>
<p>Any expression of the form <b><code> ( A | B )*+ </code></b> seems to use recursion.
<br />Can someone explain why recursion, rather than iteration, is used by the regex engine for this?
</p>
<p>Here is a demo script showing the problem:</p>
<p><code>
#!/usr/bin/perl
use strict; use warnings;
$_ = '"' . ('\"' x 100000) . '"';
print "NOT MATCHED!\n" unless
/^ " (?: [^"\\]++ | \\. )*+ " /x ; # as recommended by perlre(1)
# why does this use recursion (rather than iteration)?
#Output under perl v5.24.1:
# Complex regular subexpression recursion limit (32766) exceeded at line 6.
# NOT MATCHED!
</code></p>