Reputation: 115
I am not at all familiar with, nor have I ever had to really use regex before. I'm using some software that requires regex for "advanced filters" and I've spent the better part of 2 hours researching & trying to get this to work... I've found other posts that seem similar, but for the life of me, I cannot adapt those answers to my specific need.
Requirement: Return all results which DO NOT contain a permutation of:
ListView
List View
Listview
List view
listview
list view
listView
list View
...but would need to match anything else with more than 0 characters. I've gotten the following to work in the positive case (e.g. it successfully matches the strings above. Now I just need to negate it.
[Ll]ist[\s]?[Vv]iew
Intuitively, this seems like it should be easy... Things I've tried:
(?![Ll]ist[\s]?[Vv]iew)
(?!([Ll]ist[\s]?[Vv]iew))
(?:(?!([Ll]ist[\s]?[Vv]iew)))
Upvotes: 1
Views: 58
Reputation: 522007
Here is one pattern which seems to work:
^(?!.*\b[Ll]ist[ ]?[Vv]iew\b).*$
It uses a negative lookahead to assert that no permutation of list
+ view
occurs. You were on the right track, but the general pattern to assert that some word WORD
does not occur anywhere is this:
^(?!.*\bWORD\b)
The .*
allows for WORD
to occur anywhere.
Note that if you regex tool has a case insensitive mode, then the pattern can be simplified to this:
^(?!.*\blist[ ]?view\b).*$
Upvotes: 1