import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?!\\d*(\\d)\\d*(?:(\\d)\\d*\\1\\d*\\2|\\1\\d*(\\d)\\d*\\3)|0)(?=\\d*(\\d).*\\4)\\d{10}$";
final String string = "1134567890\n"
+ "2123456789\n"
+ "1234267890\n"
+ "1671812342\n"
+ "1934466892:6\n"
+ "1234@56789\n"
+ "3563893124\n"
+ "4412356789\n"
+ "2349780915\n"
+ "981651321182234556\n"
+ "1234567890\n"
+ "10000000000\n"
+ "02346ex789\n"
+ "0000%00000\n"
+ "0234567 894\n"
+ "8232527884\n"
+ "02325278847\n"
+ "02345678945\n"
+ "2323456789\n"
+ "8152228374\n"
+ "0234527834\n"
+ "8183746528\n"
+ "0435465768\n"
+ "3245657689\n"
+ "1223345678";
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