import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "error(?!s=)";
final String string = "1 sample text, more text, errors=123456 more text more text\n"
+ "2 drops=0 link status good errors=0 adapter\n"
+ "3 Error: process failed to start\n"
+ "4 process [ERROR] failed\n"
+ "5 this line might have both ERROR and error=5555 and more text\n"
+ "6 there might be a line that has error=0x02343329 ERROR and more text";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html