Skip to content

Instantly share code, notes, and snippets.

@OlofFredriksson
Last active December 17, 2015 02:59
Show Gist options
  • Save OlofFredriksson/5539715 to your computer and use it in GitHub Desktop.
Save OlofFredriksson/5539715 to your computer and use it in GitHub Desktop.
Javascript String Multireplace
/*
* Add a function to String prototype to do multiple regex
* Credit goes to @datanizze
* Licence: Public domain
*/
if(String.prototype.multiReplace === undefined) {
String.prototype.multiReplace = function(match, replace) {
var output = this;
for (var i in match) {
output = output.replace(new RegExp(match[i], "gi"), replace[i]);
}
return output;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment