Forum Moderators: open
Is there a way to (in jscript) call a function with a backreference to a RegExp, rather than just calling "$1" or something?
Example:
tstring="hello <@ 4-3 @>";
alert(tstring.replace(/\<\@\s{1,}(.+)\s{1,}\@\>/g, "eval($1)"));
That simply returns "eval(4-3)", and eval("$1") returns an error. So, is there a way to make sure 4-3 is evaluated (to 1)? Thanks!
For the arguments, it appears to go something like this:
1) The substring matching the entire RegExp.
2,3,..) The submatches ($n)
last arg) The entire input string
--- try it out ---
var string="abcde";
var reg = /a(b)(c)/;
var info = "";function repFn()
{
for(var k=0;k<arguments.length;k++)
info+= k+":"+arguments[k]+"\n";
}string.replace(reg,repFn)
alert(info)