$test1 = ' surrounding1 ';
$test2 = ' surrounding2 ';
$test3 = ' extra spaces between ';
A regular expression '/[ ]{2,}/'will not do the trick, because it also matches leading and trailing spaces. Until (?!\S+)\s{2,}(?!\S+) it matches all the interior spaces .
gremo source
share