title: Javascript Regex to specify what is allowed (rather than what is not)
body: <p>I've been using this:</p>
  
  <p><code>str2 = str1.replace(/[^\w]/gi, '');</code></p>
  
  <p>It works fine, but falls foul of JSLint for having an <code>insecure '^'</code> as outlined in the posts <a href="https://stackoverflow.com/questions/2372635/purpose-of-jslint-disallow-insecure-in-regex-option?rq=1">here</a> and <a href="https://stackoverflow.com/questions/4109214/jslint-insecure-in-regular-expression">here</a>.</p>
  
  <p>The consensus is that it is better to use your <code>regex</code> to specify what <em>is</em> allowed rather than what is not. No one ever demonstrates how to do this, however. I've even got Flanagan and Crockford in front of me here, but to my shame I'm still not sure what to do.</p>
  
  <p>So... how do you set <code>str2</code> to only allow the <code>\w</code> characters found in <code>str1</code> using a positive test rather than a negative one?</p>