import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?<FADECID>\\d{6})(?<MSG>([a-zA-Z0-9() -]*([;,])){7,})(?<TIME>\\d{4})?(?<FM>\\d{2})?\\4?(?<CON>.*)$";
final String string = "383154VSC X1;;;;;;;BOTH WASTE DRAIN VLV NOT CLSD (135MG;35MG);HARD;093502\n"
+ "282151FCMC1 1;;;;;;;FUEL MAIN PUMP1 (121QA1);HARD;093502\n"
+ "732112EEC2B 1;;;;;;;FMU(E2-4071KS)WRG:EEC J12 TO FMV LVDT POS,HARD;\n"
+ "383154VSC X1,,,,,,,BOTH WASTE DRAIN VLV NOT CLSD (135MG,35MG),HARD,093502\n"
+ "282151FCMC1 1,,,,,,,FUEL MAIN PUMP1 (121QA1);HARD;093502\n"
+ "732112EEC2B 1,,,,,,,FMU(E2-4071KS)WRG:EEC J12 TO FMV LVDT POS,HARD,\n"
+ "383154VSC X1,,,,,,,BOTH WASTE DRAIN VLV NOT CLSD (135MG;35MG);HARD;093502\n"
+ "282151FCMC1 1;;;;;;;FUEL MAIN PUMP1 (121QA1),HARD,093502\n"
+ "732112EEC2B 1,,,,,,,FMU(E2-4071KS)WRG:EEC J12 TO FMV LVDT POS;HARD;";
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