var count = 0;
var callback = function(x) {
return (++count) + x;
};
"あいうあいうあいう".replace(/あいう/g, callback);