title: Javascript regex for cleaning string value
body: <p>I want to strip invalid characters from a string with js.</p>
  
  <p>My regex currently is as below:</p>
  
  <pre><code>var newString = oldString.replace(/([^a-z0-9 ]+)/gi, '');
  </code></pre>
  
  <p>i.e find anything but a-z or 0-9 and spaces independent of casing and replace with nothing - however I also want to allow underscore (<code>_</code>), hyphen (<code>-</code>) and dot (<code>.</code>).</p>
  
  <p>I attempted to update my regex as below but it is not working as expected - after I made the change I found strings with brackets () were not getting those stripped?</p>
  
  <pre><code>var newString = oldString.replace(/([^a-z0-9 .-_]+)/gi, '');
  </code></pre>
  
  <p>Am I missing something simple?</p>