Regular Expression Notes

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}

About vicki

Welcome to the Sovereign Republic of Vickistan. I am the President here. Lucky me! No taxes or laws yet. Lucky you!
This entry was posted in Linux. Bookmark the permalink.