import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(.{2})(.{14}).{14}(.{8})(.{8})(.{20})(.{8})(.{1})(.{10}).{2}.{2}(.{2})(.{14}).{10}.{5}(.{16})(.{3})(.{18}).{15}.{15}.{6}.{6}.{2}.{3}.{18}.{10}(.{2}).{3}.{32}.{2}(.{10})(.{15}).{38}.{5}.{5}.{5}.{5}.{5}.{5}(.{16})(.{16})(.{20})(.{3})(.{3})(.{2})(.{20})(.{5})(.{15})(.{10}).{3}.{3}(.{2})(.{24})(.{3})(.{20})(.{2}).{24}(.{6}).{6}.{10}(.{3}).{3}.{3}(.{3})(.{3})(.{5})(.{3})(.{2}).{2}(.{5}).{2}.{20}.{5}.{20}.{2}.{3}.{2}.{5}.{325}(.{14}).{3}.{24}.{25}.{20}.{1}.{1}.{2}.{5}.{3}.{3}.{3}.{6}.{4}.{3}(.{5})(.{5})(.{3})(.{1})(.{3})";
final String string = "2422072021115242 GU32120300002689543200710020 489346250700918BE0D011 0022072021114833700918BE0D1 04D10790201AEA005 543200710020 1 5 543200310050 100 0 5 5491127654295 1 0 22072021114834 65535 655356553565535655356553565535 3 0 X700\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