Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do i find $a and replace it with $b when it's preceded by $c?

by nuance (Hermit)
on Jun 13, 2000 at 13:01 UTC ( #17850=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do i find $a and replace it with $b when it's preceded by $c? - Answer contributed by nuance

A postivive look behind clause in the regular expression will do what you want.
my($a, $b, $c, $d) = qw{foo bar moo moofooyou); $d =~ s/(?<=$c)$a/$b/g;
produces moobaryou in $d

  • Comment on Answer: How do i find $a and replace it with $b when it's preceded by $c?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[zentara]: See problems with Nvidia and Linus Torvalds
[choroba]: that's 2012
[zentara]: I just acquired a computer with the card type, and wondered if it was best to stick with the open-source code or use NVIDIA's proprietary code
[zentara]: do you feel good about a non-open-source code, being in control of your display functions?
[choroba]: If you're not going to play 3d games on it, using the open source driver should be enough

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-05-26 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?