[pcre-dev] Inconsistent behavior of some quantified groups

Top Page

Reply to this message
Author: ND
Date:  
To: Pcre-dev
Subject: [pcre-dev] Inconsistent behavior of some quantified groups

PCRE2 version 10.34-RC1 2019-04-22

/\A(?:\1b|(?=(a)))*?\z/
ab
No match

/\A(?:\1b|(?=(a)))*\z/
ab
No match


Both patterns must successfully match after second iteration.
But PCRE2 have following rule:

It is possible to construct infinite loops by following a group that can
match no characters with a quantifier that has no upper limit, for example:
(a?)*
Earlier versions of Perl and PCRE1 used to give an error at compile time
for such patterns. However, because there are cases where this can be
useful, such patterns are now accepted, but whenever an iteration of such
a group matches no characters, matching moves on to the next item in the
pattern instead of repeatedly matching an empty string. This does not
prevent backtracking into any of the iterations if a subsequent item fails
to match.


It would be nice to use some less restrictive rule. It should not assume
infinite loops in situations when there is no infinite loops.
I guess Perl have the same problem.