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?
Example: The regex "aa\n" tries to match two consecutive "a"s at the end of a line, inclusive the newline character itself. Example: "a\+" matches "a+" and not a series of one or "a"s. ^ the caret is the anchor for the start of the string, or the negation symbol.
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)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With