Skip to content

Instantly share code, notes, and snippets.

@maguay
Last active January 22, 2024 10:40
Show Gist options
  • Save maguay/f3a46f578568a608413530e27b78af88 to your computer and use it in GitHub Desktop.
Save maguay/f3a46f578568a608413530e27b78af88 to your computer and use it in GitHub Desktop.
Regex to find phone phone numbers in all standard and international formats
(?:(?:\+?([1-9]|[0-9][0-9]|[0-9][0-9][0-9])\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([0-9][1-9]|[0-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?
/a tweaked version of the second regex in the question here to allow for all country codes and leading zeros in area codes: https://stackoverflow.com/questions/3868753/find-phone-numbers-in-python-script
@eclectic-coding
Copy link

Worked beautifully. Thanks

@Rhriti
Copy link

Rhriti commented Jan 22, 2024

John's mobile number is (555) 123-4567. Won't work on this scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment