import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<ID>[A-Z0-9]{4})(?P<CATEGORY>0000[A-Z0-9]{1})(?P<TIMESTAMP>[0-9]{10})";
final String string = "D812E66E0000A13297539619F990000A1326011227538F0000A134114416231680000A1333737336D7AB0000A1367834926D1A90000A1340522218B4D40000A1339938392DD4C0000A1346574058C1A20000A134475357330810000A136293851756F20000A1329934748A71A0000A1383377560B3F90000A13460667155BBE0000A1370955439BF490000A1336724039A6E90000A132550239864440000A13827086085A3F0000A1353692293BB7C0000A136799576755110000A1327676142DA5B0000A13536535381E270000A1332164993941B0000A133802356236AF0000A1345444250FBC50000A134544825251590000A1355240920\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