We Recommend

Mastering Regular Expressions Mastering Regular Expressions
As this book shows, a command of regular expressions is an invaluable skill. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them.


Ballyhoo


Posted By

martinkas on 03/13/08


Tagged

regex phone us extension


Versions (?)


US Phone Number with extension, flexible


Published in: Regular Expression 


  1. ^((1|+1)?( |-|.)?)?((?[0-9]{3})?|[0-9]{3})( |-|.)?([a-zA-Z0-9]{3}( |-|.)?[a-zA-Z0-9]{4})[ ]*(( |x|ext|ext.|extension|Ext|Ext.|Extension|#){1}[ ]?([0-9]){1,7}){0,1}$
  2.  
  3. matched
  4. (223)456 7891 x 123
  5. (223)456 7891 ext 123
  6. (223)456 7891 ext. 123
  7. (223)456 7891 Ext 123
  8. (223)456 7891 Ext. 123
  9. (910)456-8970 x12
  10. (910)456-8970 #12
  11. (910)456-8970 extension12456
  12. (910)456-8970 Extension 12456
  13. 234.445.6789
  14. 987 765-8765
  15. 1 (453) 876 9876
  16. +1 (453) 876 9876
  17. (800)ABCDEFG
  18. (800) ABC-1234
  19.  
  20. not matched
  21. 2 (453) 876 9876
  22. (4534) 876 9876
  23. (453) 8764 9876
  24. (453) 876 98769

Report this snippet 

You need to login to post a comment.