Java regular expression – matches all strings except a few
•
Java
I have these strings in the array. I want to iterate over the array and find matching data (check one row for each match)
Bird Cat Dog Fish CatDog DogCat
Now, with regexbuddy, I have this regular expression:
(?!Cat\b)\b\w+
I want to add "dog", so try in a regular expression match and I'll get a match, you know, like an or operator I hope it can check the existence of "cat" or "dog" or "fish" at one time
Any ideas?
Solution
Try the following:
\b(?!(?:Bird|Cat|Dog|Fish|CatDog|DogCat)\b)\w+
|Character is the or operator in regular expressions
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码