需求:有字符串,‘【空格】【空格】【空格】xxx【空格】yyy【空格】【空格】’
得到有效字符串 xxx【空格】yyy
解决:使用正则表达式解决
function
(str){
return
str
.replace(/(^\s*)|(\s*$)/g,
""
);
}
另:1、得到字符串xxx【空格】yyy【空格】【空格】
解:
function(str){
return
str
.replace(/(^\s*)/g,
""
);
}
2、得到字符串
【空格】【空格】【空格】xxx【空格】yyy
解:
function
(str){
return
str
.replace(/(\s*$)/g,
""
);
}