Skip to content

Instantly share code, notes, and snippets.

@wangpin34
Last active May 18, 2016 03:24
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 wangpin34/7f081e8d5f2285cebe57380baf3d899d to your computer and use it in GitHub Desktop.
Save wangpin34/7f081e8d5f2285cebe57380baf3d899d to your computer and use it in GitHub Desktop.
trim begin and end spaces of string
function leftTrim(str){
return str.replace(/^[\s\t]+/g, '');
}
function rightTrim(str){
return str.replace(/[\s\t]+$/g, '');
}
function trim(str){
return str.replace(/(^[\s\t]+)|([\s\t]+$)/g, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment