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.
I tested it on https://www.functions-online.com/preg_replace.html and also tried some suggested Regexes like: [0-9\h+-]{6,} or preg_replace('/+?\d(?:[\s+()-]*\d){5,}/', ' [hidden] ', '+12 0 123 44 44 555');
but both still only replace part of the phone number.
(previous post where only part of the question was answered and the post was closed: Regex matching phone numbers (with PHP preg_replace) )