My problem is that I need to match if a string contains any words besides the one(s) I list.
For example, I may have this approved list:
User1
User2
Here are two examples of what should match and what shouldn’t.
Should match (because User3 is not approved):
User1
User2
User3
Shouldn’t match (because every string listed is in the approved list):
User1
I have tried lookaround assertions, but they do not actually consume the letters as they try to match, so with a string like "User1\r\nUser2", I get matches like "ser1\r\n". I want to know if there are any other words besides what I deem allowable.
I cannot use a programming language to do this; I am only allowed to hand a regular expression to the program. The language will be Perl.
Does
/\b((?!(User1\b|User2\b)).+?)\b/do what you’re looking for?\bmeans word break, i.e. the gap between a word and non-word character (zero-width).?!signifies a negative lookahead assertion (also zero-width)..+?is being used to catch anything not matching the excluded words.Hope this helps.