Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: 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=note: print w/replies, xml ) Need Help??


in reply to How do i find $a and replace it with $b when it's preceded by $c?

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 Re: 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://17850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-05-18 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?