import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?!.*(11|22|33|44|55|66|77|88|99|01|12|23|34|45|56|67|78|89|10|21|32|43|54|65|76|87|98))\\d{4}$";
final String string = "1111\n"
+ "5555\n\n"
+ "1234\n"
+ "7564\n\n"
+ "1148\n"
+ "1559\n"
+ "1499\n\n"
+ "1268\n"
+ "1569\n"
+ "1389\n\n"
+ "9851\n"
+ "9651\n"
+ "9532\n\n"
+ "1579\n"
+ "8264\n"
+ "1359\n"
+ "9461\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