Basically I need a regex which will return true if the string is a word (w+) EXCEPT if it is the word word1 OR word2.
I've tried many things but dont think I'm even close. Help!
^(?!(?:word1|word2)$)w+$
should do what you need.
(?!...) is a negative lookahead assertion that ensures that it is not possible to match the enclosed expression at the current position.
(?!...)
2.1m questions
2.1m answers
60 comments
57.0k users