I have an input string.
I am thinking how to match this string against more than one regular expression effectively.
Example Input: ABCD
I'm not sure what effectively
means, but if it's about performance and you want to check a lot of strings, I'd go for this
...
static Pattern p1 = Pattern.compile("[a-zA-Z]{3}");
static Pattern p2 = Pattern.compile("^[^\\d].*");
static Pattern p3 = Pattern.compile("([\\w&&[^b]])*");
public static boolean test(String s){
return p1.matcher(s).matches ? true:
p2.matcher(s).matches ? true:
p3.matcher(s).matches;
}
I'm not sure how it will affect performance, but combining them all in one regexp with |
could also help.