$test1 = ' surrounding1 '; // No replace
$test2 = ' surrounding2 '; // No replace
$test3 = ' extra spaces between '; // Becomes ' extra spaces between '
Regular expression '/[ ]{2,}/' won’t do the trick because matches also leading and trailing spaces. While (?!\S+)\s{2,}(?!\S+) won’t match all inner spaces.
1 Answer