please help me modify this regex
Posted: Fri Mar 23, 2012 9:23 pm
Hello,
I am using the following regex to parse text for phone numbers:
This works for (123) 456-7810, but not (123)456-7810.
Can anyone show me how to make it work for both?
Thanks in advance,
KC
I am using the following regex to parse text for phone numbers:
Code: Select all
$text="bbbbbbbbbbbbbbbbbbbbb (123) 456-7810 hhhhhhhhhhhhhhh";
$all_phones='';
preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",$text, $all_phones);
This works for (123) 456-7810, but not (123)456-7810.
Can anyone show me how to make it work for both?
Thanks in advance,
KC