var str =' hello world ';
// 去除开头的空格
str1 = str.replace(/^s*/g ,'')
//去除结尾的空格
str2 = str.replace(/s* $/g ,'')
console.log(str1)
console.log(str2)
str_target =str.replace(/^s*|s* $/g , "")
console.log(str_target)
效果图:
