title: How do I remove all whitespaces except those between words with Regular Expression in Javascript
body: <pre><code>  var str=" hello world! , this is Cecy ";
    var r1=/^\s|\s$/g;
    console.log(str.match(r1));
    console.log(str.replace(r1,''))
  </code></pre>
  
  <p>Here, the output I expect is "hello world!,this is Cecy", which means remove whitespaces in the beginning and the end of the string, and the whitespace before and after the non-word characters. 
  The output I have right now is"hello world! , this is Cecy", I don't know who to remove the whitespace before and after "," while keep whitespace between "o" and "w" (and between other word characters).</p>
  
  <p>p.s. I feel I can use group here, but don't know who</p>