import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(0|84)(2(0[3-9]|1[0-689]|2[0-25-9]|3[2-9]|4[0-9]|5[124-9]|6[0369]|7[0-7]|8[0-9]|9[012346789])|3[2-9]|5[25689]|7[06-9]|8[0-9]|9[012346789])([0-9]{7})$";
final String string = "0917123123\n"
+ "0901123123\n"
+ "0931123123\n"
+ "0891123123\n"
+ "0701123123\n"
+ "0761123123\n"
+ "0771123123\n"
+ "0781123123\n"
+ "0791123123\n"
+ "01201123123\n"
+ "01211123123\n"
+ "01221123123\n"
+ "01261123123\n"
+ "01281123123\n"
+ "0911123123\n"
+ "0941123123\n"
+ "0881123123\n"
+ "0811123123\n"
+ "0821123123\n"
+ "0831123123\n"
+ "0841123123\n"
+ "0851123123\n"
+ "01231123123\n"
+ "01241123123\n"
+ "01251123123\n"
+ "01271123123\n"
+ "01291123123\n"
+ "0961123123\n"
+ "0971123123\n"
+ "0981123123\n"
+ "0861123123\n"
+ "0321123123\n"
+ "0331123123\n"
+ "0341123123\n"
+ "0351123123\n"
+ "0361123123\n"
+ "0371123123\n"
+ "0381123123\n"
+ "0391123123\n"
+ "01621123123\n"
+ "01631123123\n"
+ "01641123123\n"
+ "01651123123\n"
+ "01661123123\n"
+ "01671123123\n"
+ "01681123123\n"
+ "01691123123\n"
+ "0921123123\n"
+ "0561123123\n"
+ "0581123123\n"
+ "0521123123\n"
+ "01881123123\n"
+ "01861123123\n"
+ "0991123123\n"
+ "0591123123\n"
+ "01991123123\n"
+ "0871123123\n"
+ "0551123123";
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