Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Answer: How do I find $a only where it's not followed by $b and then replace it with $c?

by neshura (Chaplain)
on Feb 15, 2000 at 03:19 UTC ( #3496=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I find $a only where it's not followed by $b and then replace it with $c? - Answer contributed by neshura

Use Perl's cool "zero-width negative lookahead assertion".

s/$a(?!$b)/$c/;

  • Comment on Answer: How do I find $a only where it's not followed by $b and then replace it with $c?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2016-12-04 03:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (61 votes). Check out past polls.