1

I am using Googles Phone Number Library to find phone numbers in a text file. That phone number can be in any format or from any country. Regex is not solving the problem. I was coding in 3rd party python version of it, but it is not that good and I can't find a way to use FindNumbers function. How to use it in Java or even better in python?

Here is an Example: 440-991-6659(F)

anshaj
  • 293
  • 1
  • 6
  • 24

1 Answers1

0

IN the python port that you link to, there is a PhoneNumberMatcher class that provides the FindNumbers functionality. The code is here.

From the project's README:

Sometimes, you've got a larger block of text that may or may not have some phone numbers inside it. For this, the PhoneNumberMatcher object provides the relevant functionality; you can iterate over it to retrieve a sequence of PhoneNumberMatch objects. Each of these match objects holds a PhoneNumber object together with information about where the match occurred in the original string.

>>> text = "Call me at 510-748-8230 if it's before 9:30, or on 703-4800500 after 10am."
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
...     print match
...
PhoneNumberMatch [11,23) 510-748-8230
PhoneNumberMatch [51,62) 703-4800500
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
...     print phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)
...
+15107488230
+17034800500
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153