http://www.perlmonks.org?node_id=11155516


in reply to Precise backreference semantics in Perl regular expressions

My perl disagrees.

#!/usr/bin/perl use strict; #use warnings; for my $regexp ( qr/^((a*)b|a*b?d)*c\2$/, qr/^(a*b?d|(a*)b)*c\2$/, ) { for my $string (qw( aabadcaa aababdcaa )) { print "\n$string\n$regexp\n"; print $string =~ /$regexp/ ? 'Yes' : 'No', "\n"; } } print <<END; This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-li +nux-thread-multi END

Outputs:

aabadcaa (?^:^((a*)b|a*b?d)*c\2$) No aababdcaa (?^:^((a*)b|a*b?d)*c\2$) No aabadcaa (?^:^(a*b?d|(a*)b)*c\2$) Yes aababdcaa (?^:^(a*b?d|(a*)b)*c\2$) Yes This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-li +nux-thread-multi