preg replace single space with double spaces code example
Example 1: replace multiple spaces with single space javascript
string = string.replace(/\s\s+/g, ' ');
Example 2: php replace two spaces with one
$output = preg_replace('!\s+!', ' ', $input);