1、移除字符串開(kāi)頭空格
str.replace(/(^\s*)/g, '')
2、移除字符串結(jié)尾空格
str.replace(/(\s*$)/g, '')
3、移除字符串開(kāi)頭結(jié)尾空格
str.replace(/(^\s*)|(\s*$)/g, '')
4、移除字符串結(jié)尾空格
str.replace(/\s+/g, '')
str.replace(/(^\s*)/g, '')
str.replace(/(\s*$)/g, '')
str.replace(/(^\s*)|(\s*$)/g, '')
str.replace(/\s+/g, '')