I'm trying to match a word (good) if another word (bad) does not exist in the same sentence. I want to do this using lookaround as I want only the first word (good) to be included in the captured results.
Here's my regular expression:
(?<!\bbad\b[^.])\bgood\b(?![^.]+\bbad\b)
This does work in all cases except when the word I'm looking for (good) precedes the other word (bad).
So in the following examples, the results are as follows:
- TEST 1: A good example of a bad regex. (no matches - PASS)
- TEST 2: A bad example of a good regex. (match found - FAIL)
- TEST 3: A bad example. A good regex. (match found - PASS)
- TEST 4: A good example. A bad regex. (match found - PASS)
Can someone please point me to what I'm missing here? Here's my test on regex101.com.