how to define regex (preg_replace) to removes space between number character
问题 I have string like this: $str = "old iccid : 809831 3245 345 new iccid : 999000 112221" How to define regex in order to remove the space character between number character in PHP, to become this output? $output = "old iccid : 8098313245345 new iccid : 999000112221"; i've tried to use this syntax: $output = preg_replace( '/\d[ *]\d/', '', $str); but didn't work well. 回答1: Try: $output = preg_replace('/(?<=\d)\s+(?=\d)/', '', $str); 回答2: The regex engine can traverse the string faster / with