当前位置: 代码迷 >> 综合 >> 消除空格的正则表达式
  详细解决方案

消除空格的正则表达式

热度:66   发布时间:2024-01-18 03:31:47.0
<span style="font-size:18px;">      
       var str="  word  ";//消除左边的空格alert("hello"+str);alert( "hello"+str.replace(/^\s*/g,""));//消除右边的空格alert("hello"+str+"tom");alert( "hello"+str.replace(/\s*$/g,"")+"tom");//消除前后的空格alert("hello"+str+"tom");alert( "hello"+str.replace(/(^\s*)|(\s*$)/g,"")+"tom");
</span>

  相关解决方案