jimav has asked for the wisdom of the Perl Monks concerning the following question:
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:
#!/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 li +ne 6. # NOT MATCHED!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What regex can match arbitrary-length quoted string?
by dave_the_m (Monsignor) on Sep 28, 2017 at 22:47 UTC | |
|
Re: What regex can match arbitrary-length quoted string?
by AnomalousMonk (Archbishop) on Sep 29, 2017 at 02:51 UTC | |
|
Re: What regex can match arbitrary-length quoted string?
by Anonymous Monk on Sep 28, 2017 at 22:48 UTC | |
|
Re: What regex can match arbitrary-length quoted string?
by QM (Parson) on Sep 29, 2017 at 09:48 UTC | |
by QM (Parson) on Sep 29, 2017 at 13:26 UTC | |
by Anonymous Monk on Sep 29, 2017 at 13:51 UTC | |
by QM (Parson) on Oct 03, 2017 at 10:46 UTC | |
by jimav (Sexton) on Aug 26, 2023 at 00:29 UTC |