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?
This is not easily possible. Regular expressions are designed to match things, and this is all they can do.
First off: [^]
does not designate an "excludes group", it designates a negated character class. Character classes do not support grouping in any form or shape. They support single characters (and, for convenience, character ranges). Your try [^(not|this)]
is 100% equivalent to [^)(|hinots]
, as far as the regex engine is concerned.
Three ways can lead out of this situation:
(not|this)
and exclude any matches with the help of the environment you are in (negate match results)