import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<ApplicationName>.+)\\s(?<ApplicationId>[\\w-]+)\\s(?<ApplicationType>[\\w-]+)\\s(?<StartTime>\\w{3}\\s\\w{3}[\\d:\\s]+[A-Z]+\\s\\d{4})\\s(?<EndTime>\\w{3}\\s\\w{3}[\\d:\\s]+[A-Z]+\\s\\d{4})\\s(?<FinalState>[A-Z]+)\\s(?<Queue>[^\\s]+)\\s((?<QueueUtilization>[^\\s]+)\\s)?\\w+$";
final String string = "Spark Python Pi-job application_1681357021637_0983 SPARK Wed May 3 04:32:02 MST 2023 Wed May 3 04:32:11 MST 2023 SUCCEEDED default Fine edmse2\n\n"
+ "Oozie Job on Vip 0306563-230428030149477-oozie-oozi-W Shell-Action Wed May 3 04:32:09 MST 2023 Wed May 3 04:32:17 MST 2023 SUCCEEDED default nemoqee2\n\n"
+ "Distcp job application_1681357021637_0984 MAPREDUCE Wed May 3 04:32:32 MST 2023 Wed May 3 04:32:40 MST 2023 SUCCEEDED default Fine edmse2";
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