import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[0\\+\\(][\\d\\-\\.\\+ \\)\\(\\/]{10,22}";
final String string = "(06442) 3933023\n"
+ "(02852) 5996-0\n"
+ "(042) 1818 87 9919\n"
+ "06442 / 3893023\n"
+ "06442 / 38 93 02 3\n"
+ "06442/3839023\n"
+ "042/ 88 17 890 0\n"
+ "+49 221 549144 – 79\n"
+ "+49 221 - 542194 79\n"
+ "+49 (221) - 542944 79\n"
+ "0 52 22 - 9 50 93 10\n"
+ "+49(0)121-79536 - 77\n"
+ "+49(0)2221-39938-113\n"
+ "+49 (0) 1739 906-44\n"
+ "+49 (173) 1799 806-44\n"
+ "0173173990644\n"
+ "0214154914479\n"
+ "02141 54 91 44 79\n"
+ "01517953677\n"
+ "+491517953677\n"
+ "015777953677\n"
+ "02162 - 54 91 44 79\n"
+ "(02162) 54 91 44 79\n"
+ "+49 (0) 69 707 9839-536\n"
+ "+4915254509290\n"
+ "+49 (0) 211 913583-583\n"
+ "0211 922-2404\n"
+ "(02131) 29571-16\n"
+ "07161/302-279\n"
+ "0211 477-1539\n"
+ "819508968230\n"
+ "1639576326258\n"
+ "1639576328598\n"
+ "06185754740463387\n\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