When I have something like this:
var str = \"0123\";
var i = 0;
str.replace(/(\\d)/g,function(s){i++;return s;}(\'$1\'));
alert(i);
Why doe
When you use string.replace(rx,function)
then the function is called with the following arguments:
You can read all about it here
In your case $1 equals Match1, so you can rewrite your code to the following and it should work as you desire:
var str = "0123";
var i = 0;
str.replace(/(\d)/g,function(s,m1){i++;return m1;});
alert(i);