Reputation: 99586
To match all characters except vowels, we can use [^aeiou]
.
I wonder
how to match all strings other than a particular one? For example, I want to match a string which is not dog
. So cat
, sky
, and mike
will all be matches.
how to match all strings other than a few strings, or other than a regular expression?
For example, I want to match a string which is not c.t
. So sky
and mike
will all be matches, but cat
and cut
will not be matches.
Thanks.
Upvotes: 0
Views: 120
Reputation: 41848
1. How to match all strings other than a particular one
^(?!your_string$).*$
2. How to match all strings other than a few strings
^(?!(?:string1|string2|string3)$).*$
How does that work?
(?!
to check that the string does not consists solely of the string(s) to avoid. If the negative lookahead (which is an assertion) succeeds, the .*$
matches everything to the end of the string.^
anchor at the beginning to ensure we are positioned at the beginning of the string. $
anchor inside the negative lookahead to ensure that we are excluding your_string
if it is indeed the whole string, but that we do not exclude your_string and more
Reference
Upvotes: 3