title: JavaScript Variable Name Regex
body: <p>I'm trying to write a regex that will replace all invalid characters in a JavaScript variable name with underscores (in Java).</p>
  
  <p>What I'm wanting to do is:</p>
  
  <pre><code>String jsVarName = "1inva&gt;idName".replaceAll("[a-zA-Z_$][0-9a-zA-Z_$]", "_");
  </code></pre>
  
  <p>and end up with a variable named <code>_inva_idName</code>.</p>
  
  <p>What I'm struggling to do is figure out how to make the first character different to the others. </p>
  
  <p><code>[a-zA-Z_$][0-9a-zA-Z_$]</code> are the characters I want, but I cant figure out to hook them into the correct syntax. I know JS var names can be full unicode, but I only care about about ASCII.</p>