0

So I have to write a regular expression that will match US phone numbers, which can be of the form x-xxx-xxx-xxxx or xxx-xxx-xxxx or (xxx)xxx-xxxx or xxx-xxxx. I am not sure if what I have will work though, cause I am unable to test it. Would what I have below work or is there a simpler expression?

grep '+?(1[ -])?((\d{3})[ -]|(\d{3}[ -]?)){2}\d{4}'
Cyrus
  • 69,405
  • 13
  • 65
  • 117
  • 1
    This might help: [grep with regex for phone number](http://stackoverflow.com/q/2269586/3776858) – Cyrus Sep 27 '16 at 16:59
  • 1
    See: [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/3776858) – Cyrus Sep 27 '16 at 17:00

0 Answers0