Match every word except those listed
My problem is that I need to match if the string contains any words other than the list (s) I am listing.
For example, I might have this approved list:
User1
User2
Here are two examples of what should and shouldn't.
Must match (because User3 is not approved):
User1
User2
User3
Should not be matched (because every string on the approved list):
User1
I've tried search assertions, but they don't actually consume letters as they are trying to match, so with a string like "User1\r\nUser2"
I get matches like "ser1\r\n"
. I want to know if there are other words besides what I think are valid.
I cannot use a programming language for this; I am allowed to pass a regular expression to the program. The language will be Perl.
source to share
Does /\b((?!(User1\b|User2\b)).+?)\b/
what you are looking for?
\b
means a word break, i.e. a break between a word and a character without a word (zero width).
?!
means negative expression (also zero width).
.+?
used to capture anything that doesn't match the excluded words.
Hope it helps.
source to share