德国电话号码格式的正则表达式

Man*_*n87 5 php java regex preg-match-all preg-match

我尝试从德语格式的字符串中获取电话号码。但是我没有完全发挥作用。输入文本是一个完整的HTML页面,其中包含很多内容,而不仅仅是数字。

可能的格式:

(06442) 3933023     
(02852) 5996-0       
(042) 1818 87 9919   
06442 / 3893023  
06442 / 38 93 02 3     
06442/3839023
042/ 88 17 890 0     
+49 221 549144 – 79  
+49 221 - 542194 79  
+49 (221) - 542944 79
0 52 22 - 9 50 93 10 
+49(0)121-79536 - 77 
+49(0)2221-39938-113 
+49 (0) 1739 906-44  
+49 (173) 1799 806-44
0173173990644
0214154914479
02141 54 91 44 79
01517953677
+491517953677
015777953677
02162 - 54 91 44 79
(02162) 54 91 44 79
Run Code Online (Sandbox Code Playgroud)

我试过了:

$regex =  '~(?:\+?49|0)(?:\s*\d{3}){2}\s*\d{4,10}~';
if(preg_match_all($regex, $input_imprint , $matches)){
    print_r($matches);
}
Run Code Online (Sandbox Code Playgroud)

但这不仅与几种格式匹配。我不知道要这么做

des*_*ial 7

这是一个匹配所有格式的正则表达式。然后,我建议替换所有不需要的字符,您将获得理想的结果。

(\(?([\d \-\)\–\+\/\(]+)\)?([ .\-–\/]?)([\d]+))
Run Code Online (Sandbox Code Playgroud)

如果您需要最小长度来匹配数字,请使用以下命令:

(\(?([\d \-\)\–\+\/\(]+){6,}\)?([ .\-–\/]?)([\d]+))
Run Code Online (Sandbox Code Playgroud)

https://regex101.com/r/CAVex8/143

更新,感谢您的建议@Willi Mentzel


小智 1

[0-9]*\\/*(\\+49)*[ ]*(\\([0-9]+\\))*([ ]*(-|\xe2\x80\x93)*[ ]*[0-9]+)*\n
Run Code Online (Sandbox Code Playgroud)\n\n

检查此链接: https: //regex101.com/r/CAVex8/1

\n\n

可能会引入一些误报。

\n