Perl (... (*ACCEPT) ...)+ never matches

Viewed 79

From the perlre man page:

If the "(*ACCEPT)" is inside of capturing groups then the groups are marked as ended at the point at which the "(*ACCEPT)" was encountered. For instance:

  'AB' =~ /(A (A|B(*ACCEPT)|C) D)(E)/x;

will match, and $1 will be "AB" and $2 will be "B" ...

However if the second capture group has a quantifier, the pattern never matches:

'AB' =~ /(A (A|B(*ACCEPT)|C)+ D)(E)/x or die "No match";  #dies
                            ^

Why is this? Replacing the + with * or {0,99} makes no difference. Any quantifier on a capture group which encloses the (*ACCEPT) seems to prevent the *ACCEPT from working. Thanks in advance for any help.

1 Answers

The regex doesn't match because of a bug fixed in Perl 5.36. The PCRE and PCRE2 libraries aren't affected by this bug; with the quantifier, the regex matches the "AB" in "ABCDE" and the entire string "ABDE" on regex101 website with both PCRE and PCRE2.

Related