import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^((([0-9]{3}(?![0-9]))|([a-z]{3}(?![a-z])))|(([0-9]{1,2})|([a-z]{1,2}))|-){6,}";
final String string = "1234as\n"
+ "12as32\n"
+ "09ppdj\n"
+ "ppdj09\n"
+ "12asd3\n"
+ "er123a\n"
+ "123ab2\n"
+ "2dgs23\n"
+ "123as2\n"
+ "asd12a\n"
+ "p23bgf\n"
+ "asdfdw\n"
+ "123432\n"
+ "123asd\n"
+ "ds321a\n"
+ "12asd1\n"
+ "1234aa\n"
+ "a321as\n"
+ "3asr33\n"
+ "V-127-DR 27-09-2017 t/m 26-10-2017 MEER INFO WWW.BELASTINGDIENST.NL\n\n"
+ "XX-99-99- asda sda\n"
+ "99-99-XX boekeing asdasdasd\n"
+ "99-XX-99 achrijving\n"
+ "XX-99-XX \n"
+ "deze matcht niet XX-XX-99 want het begint niet met een kenteken\n"
+ "99-XX-XX \n"
+ "99-XXX-9\n"
+ "9-XXX-99 dit is een omgschrijving van de belastingdienst\n"
+ "XX-999-X \n"
+ "X-999-XX \n"
+ "XXX-99-X";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | 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