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.
Any expression of the form ( A | B )*+ seems to use recursion.
Can someone explain why recursion, rather than iteration, is used by the regex engine for this?
Here is a demo script showing the problem:
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 li
# NOT MATCHED!