Created
August 17, 2020 09:41
-
-
Save guxuerui/ea68666e6380543aff940f563c94a91e to your computer and use it in GitHub Desktop.
正则实现trim()功能去除字符串前后空格
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 myTrim(str){ | |
let reg = /^\s+|\s+$/g; | |
return str.replace(reg,""); | |
} | |
console.log(myTrim(" abcd ")); // abcd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment