Last active
December 17, 2015 02:59
-
-
Save OlofFredriksson/5539715 to your computer and use it in GitHub Desktop.
Javascript String Multireplace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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