Find a word that doesn't come after another word with RegEx

What is a RegEx pattern that I have to use to match a specific word that doesn't come after another specific word?

For example:

I am looking for "abc" that does not appear after "xyz", so the following will match:

xxabc

p abc

And the following will not be:

xyz abc

Thanks!

+4
source share
2 answers

The easiest way is a negative lookbehind statement:

(?<!xyz)(?<!xyz )abc

, abc xyz. abc, xyz , :

^(?!xyz)*((?!xyz).)*abc

, lookbehind.

+5

- :

(?<!xyz )abc

Regular expression visualization

Debuggex

, . , JavaScript.

0

All Articles