You can backreference like this in JavaScript:
var str = \"123 $test 123\"; str = str.replace(/(\\$)([a-z]+)/gi, \"$2\");
This would (quite
Like this:
str.replace(regex, function(match, $1, $2, offset, original) { return someFunc($2); })