“function replacer(str, p1, p2, offset, s){
return str + ” - ” + p1 + ” , ” + p2;
}
“XXzzzz”.replace(/(X*)(z*)/, replacer); // returns:XXzzzz - XX , zzzz”
— anything from here jQueryに学ぶ Javascript の基礎(8) String.replace() メソッド──jQuery解読(46)