http://qs321.pair.com?node_id=1230718


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:
#!/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;
output:
mid-match:[blahj?keblah] [first][third]
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.