import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<type>[A-Z]{1})(?<subtype>[A-Z<]{1})(?<issue_country>[A-Z]{3})(?<doc_number>[A-Z0-9<]{9})(?<check_sum>[0-9]{1})(?<first_optional>[A-Z0-9<]{15})\\n(?<date_brith>[0-9]{6})(?<birth_check>[0-9{1}])(?<sex>[MF]{1})(?<expiration_date>[0-9]{6})(?<expiration_check>[0-9]{1})(?<nationality>[A-Z]{3})(?<second_optional>[A-Z0-9<]{11})(?<check_digit>[0-9]{1})\\n(?<lname>[A-Z]+)(?<lname2><[A-Z]+){0,}<<(?<spacing>[<]{0,})(?<fname>[A-Z]+)(?<mname1><[A-Z]+){0,}(?<complement><.+){0,}";
final String string = "IDCHES0002068<8<<<<<<<<<<<<<<<\n"
+ "8102287F1301014CHE<<<<<<<<<<<4\n"
+ "VADIS<<QUO<<<<<<<<<<<<<<<<<<<<\n\n"
+ "I<NLDXI020DF236123456783<<<<<<\n"
+ "7208148F1108268NLD<<<<<<<<<<<9\n"
+ "VAN<DER<STEEN<<MARIANNE<LOUISE";
final Pattern pattern = Pattern.compile(regex);
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