Skip to content

Instantly share code, notes, and snippets.

@demiro
Created August 13, 2013 12:20
Show Gist options
  • Save demiro/6220553 to your computer and use it in GitHub Desktop.
Save demiro/6220553 to your computer and use it in GitHub Desktop.
String.prototype.replaceAll = function(search, replace, ignoreCase) {
if (ignoreCase) {
var result = [];
var _string = this.toLowerCase();
var _search = search.toLowerCase();
var start = 0, match, length = _search.length;
while ((match = _string.indexOf(_search, start)) >= 0) {
result.push(this.slice(start, match));
start = match + length;
}
result.push(this.slice(start));
} else {
result = this.split(search);
}
return result.join(replace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment