import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "([+0]?[06]?)(?&sep)(36)?(?&sep)(?P<aera>1|[2-9][0-9])(?&sep)(?P<num>\\d{3})(?&sep)(\\d{2})(?'sep'[\\)\\(-\\/\\.x ]*){2}";
final String string = "+36 20 800 8848 \n"
+ "36 1 267-5260 \n"
+ "+36 1 267 5260\n"
+ "+36 24 415 351\n"
+ "06 (24) 415 351\n"
+ "6(1)415 3510\n"
+ "00361-267-5260\n"
+ "0036-1-267-5260\n"
+ "0036-1-267-52-60\n"
+ "208008848\n"
+ "20800 88-48\n"
+ "00 34 800 828\n"
+ "((06)|[\\+0]{0,2}\\s*36)\n"
+ "[+0]{0,2}(?&sep)36";
final String subst = "$3$4$5$6";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
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