fork(1) download
  1. <?php
  2.  
  3.  
  4. $str='first , second ,, third, ,fourth suffix';
  5. echo preg_replace('~\s*(?:(,)\s*)+|(\s)+~', '$1$2', $str) . PHP_EOL;
  6. echo preg_replace('~\s*(?:([,\s])\s*)+~', '$1', $str);
Success #stdin #stdout 0.02s 26312KB
stdin
Standard input is empty
stdout
first,second,third,fourth suffix
first,second,third,fourth suffix