Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: How do I avoid double substitution when replacing many patterns?

by bart (Canon)
on Jan 21, 2007 at 07:51 UTC ( #595736=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I avoid double substitution when replacing many patterns?
in thread How do I avoid double substitution when replacing many patterns?

Replace $1 ||$2 with $+. That'll contain the value of the last capture that actually matched. See perlvar:

The text matched by the last bracket of the last successful search pattern. This is useful if you don't know which one of a set of alternative patterns matched.

p.s. Originally I mistakingly had posted this as a followup to Re^2: How do I avoid double substitution when replacing many patterns?, now its sibling.


Comment on Re^2: How do I avoid double substitution when replacing many patterns?
Select or Download Code
Replies are listed 'Best First'.
Re^3: How do I avoid double substitution when replacing many patterns?
by diotalevi (Canon) on Jan 21, 2007 at 20:14 UTC

    PS, I didn't know about $+ so I'm glad you posted that in the wrong place.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-30 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls