^
|
match the start
|
$
|
match the end
|
\d
|
match any digit
|
\d*
|
0 or more digits
|
\d{5}
|
any 5 digits
|
[135]
|
1, 3, or 5
|
(13)|(17)
|
13 or 17
|
[1..5]
|
1 through 5
|
(…)
|
“captures” the
enclosed characters for referring to them in the result as $1, $2, $3, etc.
|
Examples
National dialing:
^([2-9]\d\d[2-9]\d{6})$ → +1$1 (NANP)
^0(\d{10}) → +44$1 (UK)
Include national and international dialing prefixes:
^011(\d*)
→ +$1
Extension range (e.g. 15xx-35xx):
^((1[5-9]|2[0-9]|3[0-5])\d{2})$ → +1206555$1
Avoid expressions that make the first digit optional:
^9?([2-9]\d\d[2-9]\d{6})$