I'm pretty new to java regexp and trying to compile a Pattern that simplifies this:
String str1;
String str2;
String str3;
String str4;
String str;
if ((str.contains(str1) || str.contains(str3)) &&
str.contains(str3) || str.contains(str)) {
return true;
} else {
return false;
}
I figured out I can do the OR with "|"
but how do I compile the AND?
I want to be able to compile the pattern and check many strings with good performance.
EDIT:
I got this now :
private static boolean checkPatternOR() {
String patternString = "foo" ;
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
Matcher matcher1 = pattern.matcher("foo bar");
Matcher matcher2 = pattern.matcher("something else");
System.out.println("does it match? " + (matcher1.lookingAt() && matcher2.lookingAt()));
return true;
}
How would I merge matcher1 and matcher2 into one?