I\'m pretty sure regular expressions are the way to go, but my head hurts whenever I try to work out the specific regular expression.
What regular expression do I ne
I think this regexp will do the trick (but there must be a better way to do it):
(.*(ERROR|WARNING).*parsing)|(.*parsing.*(ERROR|WARNING))
If you really want to use regular expressions, you can use the positive lookahead operator:
(?i)(?=.*?(?:ERROR|WARNING))(?=.*?parsing).*
Examples:
Pattern p = Pattern.compile("(?=.*?(?:ERROR|WARNING))(?=.*?parsing).*", Pattern.CASE_INSENSITIVE); // you can also use (?i) at the beginning
System.out.println(p.matcher("WARNING at line X doing parsing of Y").matches()); // true
System.out.println(p.matcher("An error at line X doing parsing of Y").matches()); // true
System.out.println(p.matcher("ERROR Hello parsing world").matches()); // true
System.out.println(p.matcher("A problem at line X doing parsing of Y").matches()); // false