I am stumped trying to create an Emacs regular-expression that excludes groups. [^]
excludes individual characters in a set, but I want to exclude specific sequences of characters: something like [^(not|this)]
, so that strings containing "not" or "this" are not matched.
In principle, I could write ([^n][^o][^t]|[^...])
, but is there another way that's cleaner?
First of all: [^n][^o][^t]
is not a solution. This would also exclude words like nil
([^n]
does not match), bob
([^o]
does not match) or cat
([^t]
does not match).
But it is possible to build a regular expression with basic syntax that does match strings that neither contain not
nor this
:
^([^nt]|n($|[^o]|o($|[^t]))|t($|[^h]|h($|[^i]|i($|[^s]))))*$
The pattern of this regular expression is to allow any character that is not the first character of the words or only prefixes of the words but not the whole words.