Last active
December 17, 2015 06:09
-
-
Save dmiro/5563529 to your computer and use it in GitHub Desktop.
Delete or replace all pattern occurrences
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
//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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example:
console.log('11__22_33____44'.deleteOccurrences('_'));
//11223344