-1

I guess specifically this might be about a negative look ahead.

If i had a sentence in the form of:

this is the WORD i want and I want and this is the PHRASE I DONT WANT

is there a way to use just regex to match "WORD" but only not if "PHRASE" is present? My initial idea was a negative lookahead but that is only the immediate word following. I then tried using (?:\w+(?:\s*[\,\-\'\:\/]\s*|\s+)){0,3} and other similar tricks but this would match the words in-between and not the actual phrase. Not to mention the wonkiness of + in lookarounds. Then I thought about using a grouping like [^something] but i didnt know how to do that with full words without a lookaround. I then had the idea to nest lookarounds which i found out can happen, but that still gives me the root of the problem.

Can you skip words in the matching for a lookaround and if not how would i go about solving this issue?

Because if i nest using a lookbehind I still need to skip stuff to get to WORD in order to match it.

Assume the words are arbitrary in the sentence but the key word and the key phrase is something specific.

Ian
  • 287
  • 4
  • 17

1 Answers1

0

If I understand your question, you can try:

/(?!.*PHRASE I DONT WANT)WORD/

Demo

dawg
  • 98,345
  • 23
  • 131
  • 206