On Jun 11, 3:11 pm, jay <[EMAIL PROTECTED]> wrote:
> On Jun 11, 12:26 pm, jay <[EMAIL PROTECTED]> wrote:
>
> > The following two lines work in firefox but will not evaluate in Rhino
> > (1.7 release 1 2008 03 06)
>
> > var str="This is the &#65; string and the &#66; 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
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to