var str="This is the A string and the B string";
var y=str.replace(/&#(\d+);/g,function() {return
String.fromCharCode(RegExp.$1);});
y===>This is the A string and the B string
Rhino indicates that the RegExp.$1 variable is undefined and the
String.fromCharCode -- returns char(0) to be placed into the output
string.
Anyone know why this would be the case?
Additional note:
var y=str.replace(/&#(\d+);/g,function(z) {z.search(/(\d+)/); return
String.fromCharCode(RegExp.$1);});
above line will work if the search method is called to force setting
of the RegExp.$1 variable.
All those RegExp.XX variables are non-ECMA; the following conformant
code does what you want:
var y=str.replace(/&#(\d+);/g,function(a,b) { return
String.fromCharCode(b); });
Running your sample code on a recent SpiderMonkey build gets undefined
for RegExp.$1 as well.
--N