Explaining the following regular expression:
(\d(3,4)[.-]?)+
( starts a capturing group
\ escapes the following character
d end character shorthand (match any digit in the range 0 through 9 with \d)
{ open qualifier
3 minimum quantity to match
, separate quantities
4 maximum quantity to match
} close quantifier
[ open character class
. match literal dot
– literal hyphen to match hyphen
] close character class
? zero or one quantifier
) close character class
+ one or more quantifier
Improved version:
(\d{3}[.-]?){2}\d{4}