replace words from string having more than 6 digits regex php -


i want replace words string having more 6 digits.

example:

'my contact no (432)(323)(322). other number +1239343. 1 343as32240'

to:

'my contact no [removed]. other number [removed]. 1 [removed]'

i aware of regex , preg_replace. need correct regex this.

you can use regex search:

(?<=\h|^)(?:[^\h\d]*\d){6}\s* 

and replace [removed].

breakup:

(?<=\h|^)      # loookbehind assert previous position line start or whitespace (?:            # start of non capturing group    [^\h\d]*\d  # 0 or more non-space , non-digits followed 1 digit )              # end of non capturing group {6}            # match 6 of group \s*            # followed 0 or more non-space characters 

code:

$result = preg_replace('/(?<=\h|^)(?:[^\h\d]*\d){6}\s*/', '[removed]', $str); 

regex demo


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -