Javascript String superReplace(regex, callback)
String.prototype.superReplace = function(regex, callback) { var temp = this; var output;//from w ww. j av a 2s . c o m while((output = regex.exec(this)) != null) { var what = output.shift(); var to = callback.apply(what, output); if(to != null) { temp = temp.replace(what, to); } } return temp; };