I want to creating regex to remove some matching string, the string is phone number
Example user input phone number like this:
+jfalkjfkl saj f62 81 78
It would appear that you need two operations:
Remove everything that is neither a blank nor a digit:
s/[^ \d]//g;
Remove all extra blanks:
s/ +/ /g;
If you need to remove leading and trailing blanks too:
s/^ //;
s/ $//;
(after the replace multiple blanks with a single blank).
You can use \s
to represent more space-like characters than just a blank.