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.

Replies are listed 'Best First'.
Re^2: Regex backreference without capture
by QM (Parson) on Mar 05, 2019 at 10:31 UTC
    Thanks. But I think that's too complex for any normal usage. (I'd hate to maintain that, even if I was the only coder.)

    But seriously, thanks. Maybe this will spur more ideas?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of