Last active
August 29, 2015 14:06
-
-
Save tetri/6d69863534221cd3dc66 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
based on http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript | |
according to http://jsperf.com/replace-all-vs-split-join/25 | |
*/ | |
if (!String.prototype.replaceAll) | |
String.prototype.replaceAll = function (str, find, rep) { | |
return str.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), 'g'), rep); //faster for Firefox | |
return str.split(find).join(rep); //faster for Chrome | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment