To capture any word which is NOT yellow
you can use:
\b((?!\byellow\b)\w+)\b
Question
I wanted to know, how do I capture any word which is not exactly "yellow". e.g.: "red".
I have tried the following regex:
(?!(yellow))
... but I have two problems:
Can you help me correcting my regex? Thanks!
Solution 2
To capture any word which is NOT yellow
you can use:
\b((?!\byellow\b)\w+)\b
OTHER TIPS
How about
(?!yellow$)
The inner parenthesis in your original regex are needed only if you want to capture the group
The $
ensures that only yellow
will not match. If you want to use it inside a phrase use this instead
(?!yellow\b)