import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?m)^\\[([^]]*)\\](.*\\n?(?!^\\[))*";
final String string = "[My Custom Exe][2018-05-24 11:03:01] Starting Process\n"
+ "[My Custom Exe][2018-05-24 11:03:01] Getting config\n"
+ "[My Custom Exe][2018-05-24 11:03:02] Beginning operation\n"
+ "[My Custom Exe][2018-05-24 11:03:02] Could not complete this operation, invalid inputs\n"
+ "[My Custom Exe][2018-05-24 11:03:02] Available inputs are:\n\n"
+ "- 1: Mode 1\n"
+ "- 2: Mode 2\n"
+ "- 3: Mode 3\n"
+ "- 4: Mode 4\n"
+ "- 5: Mode 5\n\n"
+ "[My Custom Exe][2018-05-24 11:03:02] Exiting Program";
final Pattern pattern = Pattern.compile(regex);
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