Skip to content

Instantly share code, notes, and snippets.

@anovsiradj
Last active May 29, 2023 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anovsiradj/bc72ea2c3d2dd692411b to your computer and use it in GitHub Desktop.
Save anovsiradj/bc72ea2c3d2dd692411b to your computer and use it in GitHub Desktop.
// @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