Suppose I have two lists of words and I have to match all words in the first list but none in the second list. Now suppose all the words in the second list (those that are not to be matched) contain specific pattern: character1 followed by character2 then character2 and character1 again. For example, it contains such words as "abba", "otto", "trillion", "unfitting", etc.
I could easily match this pattern by using regex expression (\w)(\w)\2\1
. And to match all the words in the second list I could use \w*(\w)(\w)\2\1\w*
. But how do I match all words EXCEPT those containing this pattern?
One of the things I tried is (?!\w*(\w)(\w)\2\1\w*)
, but, for some reason it also matches the transition between first and second characters in the second list. I know I'm doing something wrong but I can't figure out what.