import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\b\\d\\d[-|\\s]\\d\\b)\\s(\\b[a-z]+\\b)";
final String string = "57-61 P D DeS, 62-4 Dodge 880, 57-64 C\n\n\n\n\n\n\n\n"
+ "39-56 P, D, 40-52 DeS, 53-4 DeS except wagon, 55-6 DeS Fireflite, 55-6 DeS Firedome except wagon, 40-52 C 6 cyl, 53-6 C except Imp, wagon, LWB\n\n"
+ "57-8 C, I, 60 with model E AC, PP2, PD4, High Performance, PD1, PD2, PS1, PS3, PC1, PC2, PC3, PY1, 61 with model F AC RP2 Hipo, DeS, C, Imp, 61 Dart 6, 62 P, D 6 without air, 62 C 300 and Newport, 62 P, D with 361, 63 P, D 6 62 P Valiant, Lancer with model G AC, 64 Val, Dart 273, 318, VD2 361, 383 with air and towing, 65 P, D all with 273, 318 and no air, 63-8 DT C500 with 318 and air, 69 P, D exc. Belv. Cor, 70-72 B,J,R,W with 318, 73 B,J,R,W,P,D with 318, 360";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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