Regular Expressions 101

Community Patterns

Regex Pattern for Mexico Phone Number using Groups

0

Regular Expression
PCRE (PHP <7.3)

/
(\\+?52[\\s\\-]?)
/

Description

Can anyone help me format the following regex for Mexico Phone Numbers. I have two issues, the Regular Expression builder is telling me my Grouping is invalid and also I am having trouble with the 52 pattern. I want it to allow any two digits such as [0-9]{2}

example: 52-555-786-2300

(\+?1[\s\-]?)?\(?([0-9]{3})\)?[-. ]([0-9]{3})[-. ]([0-9]{4})(\s*(x|ext)\.?\s*([0-9]+))?

Submitted by kingpoop - 9 years ago