import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "((?:\\d{2}:)?\\d{2}:\\d{2}\\.\\d{3})[^\\n]+level[^\\d]+(\\d{3})";
final String string = "00:00.300 ID:4 zzzzzzzzzzz \n"
+ "00:02.155 ID:4 aaaaaaaaaaaaa \n"
+ "00:04.662 ID:4 dsadasd \n"
+ "**00:32.283** ID:4 level **790** \n"
+ "00:32.155 ID:4 Sfghgfs \n"
+ "00:32.200 ID:4 Tsdfsdfdfsff \n"
+ "**00:32.205** ID:4 level **640** \n"
+ "00:32.206 ID:4 Sadssd \n"
+ "00:32.208 ID:4 asdasgsfgsgsagsa \n"
+ "00:32.210 ID:4 adasgx \n"
+ "00:32.212 ID:4 Masddasdas. \n"
+ "**01:40:40.698** ID:4 level **500**";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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