title: Regex - Remove everything from a string that does not match an expression
body: <p>I am creating a JavaScript function that will take a user inputted value and and create a CSS class name out of it. The following expression can be used to detect whether the end result follows valid css rules</p>
  
  <pre><code>-?[_a-zA-Z]+[_a-zA-Z0-9-]*
  </code></pre>
  
  <p>but I need to find a way to use it to remove all invalid characters.</p>
  
  <p>I was thinking of something like:</p>
  
  <pre><code>var newClass = userInput.replace(EVERYTHING BUT /[_a-zA-Z0-9-]/, "");
  </code></pre>