I want to match all strings except the string "ABC"
. Example:
"A" --> Match "F" --> Match "AABC" --> Match "ABCC" --> Match "CBA" --> Match "ABC" --> No match
I tried with [^ABC]
, but it ignores "CBA"
(and others).
Following example shows how to search duplicate words in a regular expression by using p. matcher() method and m. group() method of regex. Matcher class.
To match any character except a list of excluded characters, put the excluded charaters between [^ and ] . The caret ^ must immediately follow the [ or else it stands for just itself.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
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. Example: "^a" matches "a" at the start of the string. Example: "[^0-9]" matches any non digit.
^(?!ABC$).*
matches all strings except ABC
.
Judging by you examples, I think you mean "all strings except those containing the word ABC".
Try this:
^(?!.*\bABC\b)
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