Regex to find phone numbers in every format

I couldn’t find a truly universal regular expression (regex) to match phone numbers, no matter from which country and in which format. They all seemed to be limited in some way. Even named entity extraction APIs require you to set a country to find phone numbers.

In the end I rolled my own regex. It simply looks for a certain amount of numbers and characters generally used to make phone numbers human-readable. If you are looking to match longer or shorter numbers, you can just change the quantifiers. Some examples it will match:

540 297 1860
+886-2-8663-8287
0870882993
0090 530 229 12 04
+66 (0) 28340463
058 218 0600
(2014-2015
062-21-8608888
886-5-2781880
011-81-27372-9341
03- 7722 5012
+886-2-8663-8287
+62 – 21 – 5694 2002
+34 918 380 082
+90 532 643 34 34
+7 495 228 3513
+ 7 702 270 38 13 + 7 777

While not matching:

9:00-17:00
2015(15:00

And here the regex:

(?!.*[a-zA-Z\,:])(?=(\D*\d){7,14})([\+\d\(]{1,2}.{6,23}\d)

To use it in Python

import re

rex = '(?!.*[a-zA-Z\,:])(?=(\D*\d){7,14})([\+\d\(]{1,2}.{6,23}\d)'
numbers = re.findall(rex, str_with_phone_numbers)

 

Let me know, if this is useful for you or if you find space for improvement. Currently the biggest issue I see is that the matching ranges between numbers and total chars are unrelated. Due to many filling chars higher values are needed. Those can lead to false negatives. Best test it for yourself.