Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Regex backreference without capture

by rsFalse (Hermit)
on Mar 01, 2019 at 15:52 UTC ( #1230718=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1230718]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-01-21 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?