Last active
May 18, 2016 03:24
-
-
Save wangpin34/7f081e8d5f2285cebe57380baf3d899d to your computer and use it in GitHub Desktop.
trim begin and end spaces of string
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
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