87,910
社区成员
发帖
与我相关
我的任务
分享
str = str.replace(/^\s*|\s*$|\s*([)(,\s])\s*/g, "$1");
<script>
var re=/\s*([)(,\s])\s*/g;
var str1=" astring( ( 10 20 ) , (20 15) , (20 15 ) )"
var str2=" bstring( ( 10 10, 10 20, 20 20, 20 15, 10 10) , (20 15, 5 5, 10 10, 20 15) ) "
var str3=" cstring( ( 10 10 ,20 15 ) ,( 10 10 ,20 15 ,5 7) ) "
document.write(str1.replace(re, "$1")+"测试还有空格没")
document.write("<br>")
document.write(str2.replace(re, "$1")+"测试还有空格没")
document.write("<br>")
document.write(str3.replace(re, "$1")+"测试还有空格没")
</script>