import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[\\dA-F]+[ \\t]+[\\dA-F]+(?: [\\dA-F]+)*[ \\t]+";
final String string = "0 4D1F 8172 DC.L $4D1F8172 ; Rom CheckSum\n"
+ "4 0040 002A DC.L $0040002A ; Boot Vector = EBootStart\n"
+ "8 00 DC.B $00 ; Machine Type\n"
+ "9 75 DC.B $75 ; Rom Version\n"
+ "A 6000 0056 Bra L3\n"
+ "E 6000 0750 Bra L62\n"
+ "12 6000 0044 Bra L2\n"
+ "16 6000 0016 Bra E_6\n"
+ "1A 0001 76F8 DC.L $000176F8 ; offset of Resources in ROM\n"
+ "1E 4EFA 2BFC Jmp P_mvDoEject\n"
+ "22 0000 0000 DC.L $00000000\n"
+ "26 0000 0000 DC.L $00000000\n\n"
+ "1FFE2 4B57 4B20 4C41 DC.B 'KWK LA'";
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