Hi kc,
Sure!
You need a question mark after the [\-\s]
Without it, it says "if we've matched 3 digits, then match a space or a dash.
Cleaned up, it could look like this:
$string='(123) 456-7810 (123)456-7810";';
$regex=',\(?(\d{3})?\)?(?(1)[-\s]?)\d{3}-\d{4},';
preg_match_all($regex,$string,$m);
var_dump($m[0]);
Output:array(2) { [0]=> string(14) "(123) 456-7810" [1]=> string(13) "(123)456-7810" }
Also, if you don't need to use the area code on its own, then I might bring the parentheses inside Group 1: change the pattern line to
$regex=',(\(?\d{3}?\)?)(?(1)[-\s]?)\d{3}-\d{4},';
Let me know if you have any questions!