Reputation: 187499
I need to define a (Java) regex that will match any string that does NOT contain any of these
Is it possible to express this as a single regex? I know it would be more readable to use 3 separate regexs, but I'd like to do it in one if possible.
Thanks, Don
Upvotes: 1
Views: 184
Reputation: 29096
Try the following:
final private static Pattern p = Pattern.compile(".*\\b(?:foos?|bars?|bazs?)\\b.*");
public boolean isGoodString(String stringToTest) {
return !p.matcher(stringToTest).matches();
}
Upvotes: 6