Skip to content

Instantly share code, notes, and snippets.

@electricg
Created January 20, 2013 11:51
Show Gist options
  • Save electricg/4578106 to your computer and use it in GitHub Desktop.
Save electricg/4578106 to your computer and use it in GitHub Desktop.
Trim any given character from a string
String.prototype.trimChar = function (find) {
var reg = new RegExp("^[" + find + "]+|[" + find + "]+$", "g");
return this.replace(reg, '');
}
String.prototype.ltrimChar = function (find) {
var reg = new RegExp("^[" + find + "]+", "g");
return this.replace(reg, '');
}
String.prototype.rtrimChar = function (find) {
var reg = new RegExp("[" + find + "]+$", "g");
return this.replace(reg, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment