FAQ
# New Ticket Created by Nathan Trapuzzano
# Please include the string: [perl #121299]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=121299 >


This bug report corresponds to the discussion at:
http://www.nntp.perl.org/group/perl.perl5.porters/2014/02/msg212894.html

Perl (5.16.3 and 5.18.1 at least) doesn't always handle backreferences
inside subpattern calls correctly. For example,

   say 'fofof' =~ /(.)((o)\1)(?2)/ ? 'true' : 'false'
   ==> true

   say 'fffffff' =~ /(.)(?2)((\1)(?4)(\1))/ ? 'true' : 'false'
   ==> false

   say 'foffoff' =~ /(.)(?2)((.)(?4)(\1))/ ? 'true' : 'false'
   ==> false

"use re 'debug'" shows that the second and third examples fail at the
first '\1' encounter, as though the first capture were being reset upon
entering the sub call. However, in the first example, the capture is
cearly retained in the '(?2)' call.

A similar (same?) problem occurs with forward or self-referential
backreferences:

   print 'abcb' =~ /^(.\2?)(.)(?1)$/ ? "true\n" : "false\n"
   => false

   print 'abcb' =~ /^(.(?{ printf "%d, $2\n", pos()})\2?)(.)(?1)$/ ? "true\n" : "false\n"
   => 1,
   => 3, b
   => false

   print 'aba' =~ /^(.\1?)(?1)$/ ? "true\n" : "false\n"
   => false

   print 'aba' =~ /^(.(?{printf "%d, $1\n", pos()})\1?)(?1)$/ ? "true\n" : "false\n"
   => 1,
   => 2, a
   => false

In second example immediately above, the diagnostics say that we're
about to try to match 'b' at pos 3, which should succeed. Ditto for the
fourth example.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 10 of 39 | next ›
Discussion Overview
groupperl5-porters @
categoriesperl
postedFeb 16, '14 at 12:30p
activeFeb 26, '14 at 10:24a
posts39
users6
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase