import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\b(\\d(?=\\w{5})\\d+[A-Z][A-Z\\d]*) (.*)";
final String string = "AT exempt acc to ยงยง 4 Nr. 1A UStG iVm 6 USTG\n"
+ " 254,49/100L 977,23\n"
+ "159C5F Magnatec St-St 0W-30 D, 20L E4 0,00%\n"
+ "Commodity Code :\n\n"
+ "12333A \n"
+ "159C5F Magnatec St-St 0W-30 D, 20L E4\n"
+ "159432 Magnatec St-St 0W-30 D, 20L E4 --> Number only.\n"
+ "1AAAAA Magnatec St-St 0W-30 D, 20L E4 --> Starts with one digit.";
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