Regular Expressions 101

Community Patterns

phone number

-2

Regular Expression
Python

r"
(?:(\+?\d{1,3}) )?(?:([\(]?\d+[\)]?)[ -])?(\d{1,5}[\- ]?\d{1,5})
"

Description

An extremely complete regex, that...

  • Accepts international phones and most of regional phone numbers;
  • Accepts phone numbers with/without "+", with/without space or "-" in the middle of the phone, and more.
  • Gets groups of all important data of the phone number (local code, country code and the phone number itself)
Submitted by @thegamerbr1 - 8 years ago