O'Reilly logo
  • Henry Huang thinks this is interesting:

echo "(555) 123-4567" | grep -E '^\(?[0-9][0-9][0-9]\)? [0-9] [0-9][0-9]$' (555) 123-4567 [me@linuxbox ˜]$ echo "555 123-4567" | grep -E '^\(?[0-9][0-9][0-9]\)? [0-9] [0-9][0-9]-[0-9][0-9][0-9][0-9]$' 555 123-4567 [me@linuxbox ˜]$ echo "AAA 123-4567" | grep -E '^\(?[0-9][0-9][0-9]\)? [0-9] [0-9][0-9]-[0-9][0-9][0-9][0-9]$' [me@linuxbox ˜]$

From

Cover of The Linux Command Line

Note

Should try it out