in reply to Regex backreference without capture
Hello, QM,
Haven't heard about such capture groups for only backreferences.
Interestingly, if any simple overcome exist? This overcome below looks ugly:
Haven't heard about such capture groups for only backreferences.
Interestingly, if any simple overcome exist? This overcome below looks ugly:
output:#!/usr/bin/perl -wl print map "[$_]", "bogus firstblahj?keblahthird bogus" =~ / (?| (*F) | first ( (blah) .*? \2 ) third (?{ $L = $1 }) (*THEN) (*F) # 1 2 2 1 | (??{ defined $L ? "" : "(*F)" }) (first) (??{ print "mid-match:[$L]" ; quotemeta $L }) (third +) # 1 1 2 +2 ) /x;
Idea here is to use conditional '(?|...)' with 2 groups, save mid-match (if full match is successful), fail first branch anyway, then match same thing on alternative branch rewriting $1 and $2, and using previously defined mid-match to avoid captures.mid-match:[blahj?keblah] [first][third]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regex backreference without capture
by QM (Parson) on Mar 05, 2019 at 10:31 UTC |
In Section
Seekers of Perl Wisdom