develooper Front page | perl.perl5.porters | Postings from November 2010

Re: [perl #76622] Regex recursion and backreference: 11 !~ /(^)(|1(?2)\1)$/

Thread Previous
Zsbán Ambrus
November 21, 2010 04:57
Re: [perl #76622] Regex recursion and backreference: 11 !~ /(^)(|1(?2)\1)$/
Message ID:
It turns out that this is not a bug.

Perl behaves correctly in this case.  The explanation is that contents
of capture buffers of the topmost re are not accessible from recursed
subpatterns.  This is mentioned in perlre actually:

"(?PARNO)" ...
Capture buffers contained by the pattern will have the value as
determined by the outermost recursion.

Thus, when the regex engine recurses to subpattern 2, capture 1 has
never matched, and thus a backreference to it fails no matter what.

You can save the obfu the following way, which works in at least perl
5.10.0, 5.10.1, 5.12.0, 5.12.1, 5.13.6:

perl -le'$==0,(1x$_)=~
print$=for 0..13'

Please mark the ticket as not a bug, and sorry for the bother,


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About