Regex to replace substring only if the word does not contain a specefic substring

Viewed 22

I want to replace org in word but only if it does not contains the substring gross. For ex

org_selling -> original_selling

but

org_selling_gross -> org_selling_gross
1 Answers

You might find that the following logic works:

Find:    org_(?!\w*gross)
Replace: original_

The regex find pattern says to match:

  • org_
  • (?!\w*gross) assert that "gross" does NOT appear in following substring

Here is a working demo.

Related