0

I would like to extract these phone number patterns using regex:

xxx.xxx.xxx, xxx-xxx-xxx, (xxx)xxx-xxxx, or (xxx) xxx-xxxx

I've done this:

preg_match_all('/\b[0-9]{3}\s*-\s*[0-9]{3}\s*-\s*[0-9]{4}\b/',$output,$matches);

But it only matches xxx-xxx-xxx your help would be appreciated. thanks!

Knide
  • 111
  • 1
  • 7

1 Answers1

2
(?:\(|\b)[0-9]{3}\s*\)?[.-]?\s*[0-9]{3}\s*[.-]\s*[0-9]{3,4}\b

This should do it for you.See demo.

https://regex101.com/r/iJ7bT6/17

vks
  • 67,027
  • 10
  • 91
  • 124