title: JavaScript - string regex backreferences
body: <p>You can backreference like this in JavaScript:</p>
  
  <pre><code>var str = "123 $test 123";
  str = str.replace(/(\$)([a-z]+)/gi, "$2");
  </code></pre>
  
  <p>This would (quite silly) replace "$test" with "test". But imagine I'd like to pass the resulting string of $2 into a function, which returns another value. I tried doing this, but instead of getting the string "test", I get "$2". Is there a way to achieve this?</p>
  
  <pre><code>// Instead of getting "$2" passed into somefunc, I want "test"
  // (i.e. the result of the regex)
  str = str.replace(/(\$)([a-z]+)/gi, somefunc("$2"));
  </code></pre>