Assuming the input string +123-321+123 345
, using PHP's regex functions I would like to remove all non-digit ([^\d]
) characters, except the +
character at the start. The +
may or may not be present, so given the string 123-321+123 345
the result should be the same (123321123345
).
Currently the workaround in place is to check for the +
, then run preg_replace('/[^\d]+/', '', $string)
, but I'm sure there must be a pure regex solution to this problem.
Thanks!