So ive been using preg_replace in PHP to match and replace phone numbers.
My goal is quite simple: i want to match all character sequences which contain spaces, numbers, dashes and + sign with a minimum length of 6, so a character sequence of +12 0 123 44 44 555 would match.
String length of the $subject can be up to 1000 characters, if that makes a difference.
i came up with this regex:
preg_replace('/[0-9 +-]{6,}/', ' [hidden] ', '+12 0 123 44 44 555', -1, $count);
my expectation is i get a string of
[hidden]
what i get is
[hidden] 44 555
Im sure its obvious but i cant seem to figure out why the whole sequence doesent match.
Additionally i want to include the characters “(” and “)” in the regex so “+12 (0) 123 44 44 555” would match as well. It seems i have to double escape the ( and the ) so i have a regex which looks like this:
/[0-9 +-\(\)]{6,}/