Regex not operator
Solution 1:
Not quite, although generally you can usually use some workaround on one of the forms
-
[^abc]
, which is character by character nota
orb
orc
, - or negative lookahead:
a(?!b)
, which isa
not followed byb
- or negative lookbehind:
(?<!a)b
, which isb
not preceeded bya
Solution 2:
No, there's no direct not operator. At least not the way you hope for.
You can use a zero-width negative lookahead, however:
\((?!2001)[0-9a-zA-z _\.\-:]*\)
The (?!...)
part means "only match if the text following (hence: lookahead) this doesn't (hence: negative) match this. But it doesn't actually consume the characters it matches (hence: zero-width).
There are actually 4 combinations of lookarounds with 2 axes:
- lookbehind / lookahead : specifies if the characters before or after the point are considered
- positive / negative : specifies if the characters must match or must not match.