import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(\\d{2})\\s(\\d.\\d)\\s(\\w+(?:-+\\w+)*(?:--\\w)?-?)\\s((?:\\d+,)?\\d+.\\d+)\\s((?:\\d+,)?\\d+.\\d+)$";
final String string = "69 1.0 PKS-EKC-FlYCTRK--Y 2,110.28 2,110.28\n\n"
+ "70 2.0 ACS-PMM 31.75 63.50\n\n"
+ "72 1.0 PKS-TR1-CRD 308.14 308.14\n\n"
+ "73 1.0 QTC-01HZZ-RBER058- 1,725.57 1,725.57\n\n"
+ "74 1.0 MGS-05B-4TC-120--8 1,222.84 1,222.84\n\n"
+ "75 1.0 ACS-VGY 98.60 98.60\n\n"
+ "76 2.0 ACS-VGG 27.27 54.53\n\n"
+ "77 2.0 ACS-VGQ 110.93 221.86\n\n"
+ "78 2.0 ECS-ENM--845 1,294.18 2,588.36\n\n"
+ "80 1.0 FREIGHT 4,188.00 4,188.00\n\n";
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