title: Regex for replacing all special characters and spaces in a string with hyphens
body: <p>I have a string in which I need to replace all the special characters "~!@#$%^&amp;*()_+=`{}[]|:;'&lt;>,./?" and spaces with hyphens. Multiple special characters in a row should result in a single hyphen.</p>
  
  <pre><code>var mystring="Need !@#$%^\" to /replace  this*(){}{}|\&gt;&lt;? with_new string ";
  // desired output: "Need-to-replace-this-with-new-string"
  </code></pre>
  
  <p>At present, I'm using this series of <code>replace()</code> calls:</p>
  
  <pre><code>return mystring.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-').replace(/\//g, "-");
  </code></pre>
  
  <p>But it's outputting this:</p>
  
  <pre><code>Need----------to/replace-this--------with-new-string;
  </code></pre>
  
  <p>where it's adding a hyphen for every special character in the string except for the forward slash.</p>