The reason why your version won't work is because regexp.$1 is evaluated once when that line is run.
However, you can still do this without a for-loop and lots of replace calls. JScript allows you to pass a
function as second parameter for replace, whose return value will be used as replacement for each match. When using regular expressions, it'll even give you all the good stuff through the function's arguments!
js code:
var output = input.replace(regex, function(match, $1) {
// You could do literally anything here!
return ($1 in some_variables) ? some_variables[$1] : '';
});