develooper Front page | perl.perl5.porters | Postings from December 2016

[perl #3589] Regexp behavior in matching backreferences to optionalcaptures

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
December 28, 2016 02:16
Subject:
[perl #3589] Regexp behavior in matching backreferences to optionalcaptures
Message ID:
rt-4.0.24-4765-1482891359-1849.3589-15-0@perl.org
On Sun, 25 Jul 2010 19:21:33 GMT, greerga wrote:
> The remaining part of this ticket is clarifying in the documentation the
> behavior of back-references to optional captures.  For example:
> 
> ./perl -Ilib -wle '/^((.)?a\2)+$/ and print "$_: -$1-$2-" for qw/
> babadad /' 
> 
> does not match, because the "\2" always fails (rather than allowing an
> empty match) if the "." didn't match.  However:
> 
> ./perl -Ilib -wle '/^((.?)a\2)+$/ and print "$_: -$1-$2-" for qw/
> babadad /' 
> 
> does match, because an empty result is valid in the capture.

I believe this ticket is closable because the additional documentation needed was, in my reading, added by Karl Williamson in commit d8b950dc in June 2010.  'pod/perlre.pod' has a section on Capture Groups which contains this:

#####
The bracketing construct "( ... )" creates capture groups
(also referred to as capture buffers). To refer to the
current contents of a group later on, within the same
pattern, use "\g1" (or "\g{1}") for the first, "\g2" (or
"\g{2}") for the second, and so on. This is called a
*backreference*. There is no limit to the number of captured
substrings that you may use. Groups are numbered with the
leftmost open parenthesis being number 1, etc. If a group
did not match, the associated backreference won't match
either. (This can happen if the group is optional, or in a
different branch of an alternation.)
#####

I'll put this ticket out of its misery within 7 days unless someone wants to carry on the discussion.

Thank you very much.


-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=3589

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About