Author: ph10 Date: To: ND CC: Pcre-dev Subject: Re: [pcre-dev] Inconsistent behavior of some quantified groups
On Mon, 4 May 2020, ND via Pcre-dev wrote:
> /\A(?:\1b|(?=(a)))*\z/
> ab
> No match
>
>
> Both patterns must successfully match after second iteration.
Perl does exactly the same as PCRE. The problem is that analysing the
pattern to discover that matching nothing in one branch might make a
different branch match something on iteration, and then checking next
time that it *has* made a difference, is beyond the capability of PCRE
(and presumably Perl). If instead of "ab" you had "aa" it would be an
infinite loop.
There is already an item on the wish list about this. What it needs is a
way of telling that something has changed during an iteration. If
nothing changes, then you have a loop. This needs remembering much more
state than PCRE currently does, and in fact "something has changed" is
not sufficient; you also have to be able to detect a cycle of changes.
Because of the say PCRE is coded, the current state is unlikely to
change.