Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// @param st: The string that will be trimmed. @default whitespace
String.prototype.strim = function(st) {
st = st || "\\s";
return this.replace(new RegExp("^"+st+"+|"+st+"+$",'g'),'');
}
/*
example:
"alorem ipsuma".strim('a'); // return "lorem ipsum"
" lorem ipsum ".strim(); // return "lorem ipsum"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment