Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2016-03-29 20:31
Flavor·PCRE (Legacy)

/
\D?[0-9]{3}\D?\s?[0-9]{3}\D?\s?[0-9]{4}
/
gmi
Open regex in editor

Description

we know phone numbers are [one group of 3 numbers] [another group of 3 numbers] [a group of 4 numbers]

we use D? as a way to find nondigits like the parenthesis

This should also work: (?\d{3})?\s?-?.?\d{3}\

Submitted by anonymous