-1

I am looking for a regex that finds the match only and only if either the word KO or the word OK is not present within the string (regardless of what is before and after).

I tried this:

[^OK|KO]

But it doesn't work.

example of what I would like to match:

  •                   20032023
    

example of what I would like NOT to match:

  • 20032023 KO
  • OK 123456 20032023
Andy
  • 15
  • 1
  • Try: `(?!.*\b(OK|KO)\b).+` – anubhava Mar 20 '23 at 16:20
  • 1
    `[^OK|KO]` matches exactly one character, any character except for `O`, `K` or `|` (which are the characters listed in the character class after the starting `^`; the duplicates are ignored.) – axiac Mar 20 '23 at 16:24

1 Answers1

0

I think you are looking for something like this (?!.*(OK|KO).*)^.+$. here ^.+$ is a main match (it matches whole lines), and (!?....) piece makes the negation, so matches that also contain OK|KO won't be taken

Andrei
  • 10,117
  • 13
  • 21