Reputation: 11876
I have the following regex which I use to find a word:
(?<=\s)([\w\@\-]+)(?=\s)
I want to further modify this regex to exclude a list of words e.g. do not match if the word is 'cat' or 'dog'.
How do I accomodate the regex to achieve this?
Upvotes: 2
Views: 497
Reputation: 6740
\b(?!(?:dog|cat)\b)([\w@-]+)\b
Here if you want to match word start/end with @
(?<=\s)(?!(?:dog|cat)(?=\s))([\w\@\-]+)(?=\s)
Upvotes: 7