title: Differences between \W, \\W, [^a-zA-Z0-9_] in regular expression
body: <p>I am trying to find all characters, which are not letters(upper/lowercase), numbers, and underscore, and remove it.</p>
  <pre class="lang-java prettyprint-override"><code>stringA.replaceAll(&quot;[^a-zA-Z0-9_]&quot;,&quot;&quot;)   // works perfectly fine
  </code></pre>
  <p>However, the following code could not even compile in Java:</p>
  <pre class="lang-java prettyprint-override"><code>stringA.replaceAll(&quot;\W&quot;,&quot;&quot;);
  // or also
  stringA.replaceAll(&quot;[\W]&quot;,&quot;&quot;);
  // or also
  stringA.replaceAll(&quot;[\\W]&quot;,&quot;&quot;);
  </code></pre>
  <p>If I use only <code>&quot;\\W&quot;</code> rather than <code>&quot;\W&quot;</code>, the above code turns out to be correct. <br />
  So, what is the differences between <code>\W</code>, <code>\\W</code>, and when to use brackets like <code>[^a-zA-Z0-9_]</code></p>