title: How do I count inside of a javascript regular expression?
body: <p>How do I stick a counter in a javascript regular expression substitution?</p>
  
  <p>The question is <a href="https://stackoverflow.com/a/4214173/823263">answered here</a> for Perl/PCREs.</p>
  
  <p>I've tried the obvious <code>string.replace(/from/g, "to "+(++count))</code>, which is no good (the ++count is evaluated once at the start of the string.replace, it seems).</p>