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.
(?!...)
1.4m articles
1.4m replys
5 comments
57.0k users