Hi Jang, It looks like they are confusing the \1 find operator with the $1 operator. In your example, you would use this for the replacement and it works:
var regex = /Fred([0-9])XXX/;
var string = "Fred2XXX";
alert (string.replace(regex, "Sam$1YYY"));
The \1, \2, etc. operators are used on the find side. For example, let's say I have this:
var string = "<p>This is a paragraph with <em>emphasized</em> text.</p>";
var regex = /<[^>]+>.+?<\/[^>]+>/;
alert (string.match (regex)[0]);
The alert gives me this:
<p>This is a paragraph with <em>emphasized</em>
I don't get a matching open and close tag. To insure that my close tag matches the open tag, I need to capture the open tag and use the \1 in the close tag to get a matched set.
var string = "<p>This is a paragraph with <em>emphasized</em> text.</p>";
var regex = /<([^>]+)>.+?<\/\1>/;
alert (string.match (regex)[0]);
Now I get this
<p>This is a paragraph with <em>emphasized</em> text.</p>
which is what I want.
-- Rick