Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active December 17, 2015 06:09
Show Gist options
  • Save dmiro/5563529 to your computer and use it in GitHub Desktop.
Save dmiro/5563529 to your computer and use it in GitHub Desktop.
Delete or replace all pattern occurrences
//delete all pattern occurrences
String.prototype.deleteOccurrences = function (pattern) {
return this.str.replace (RegExp(pattern,'gi'),"");
};
//replace all pattern occurrences
String.prototype.replaceOccurrences = function (pattern, replace) {
return this.str.replace (RegExp(pattern,'gi'),replace);
};
@dmiro
Copy link
Author

dmiro commented May 12, 2013

example:

console.log('11__22_33____44'.deleteOccurrences('_'));
//11223344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment