Regex that contains but doesn't start with

Advertisements

I need some help creating a regular expression to locate a bunch of instances of code that need to be refactored. The thing is there are hundreds of places that have already been updated and the code is similar so I’m struggling to come up with a regex that finds only the ones that I need to update.

I’m basically looking to change all instances of:

confirm(...

to

w360.confirm(...

So I need a regex that will locate all instances of the first while not including the instances of the second.

>Solution :

You can easily do it with a negative look-behind:

(?<!\.)confirm\(

Leave a ReplyCancel reply