正则匹配 去掉字符串左右空格

   // str = "   hello    "
    /**
     * 去除 掉 字符串中的空格
     *   使用 "" 来替换空格
     * */   
    //  console.log(str)
     // 去除 开头的空格
    // str = str.replace(/^\s*/,"")   
    //console.log(str)  
    // 去除 结尾的空格
    // str = str.replace(/\s*$/,"")       
   // console.log(str) 
   // /^\s+|\s*$/ 匹配开头和结尾的空格
    // str = str.replace(/^\s+|\s*$/g,"")  
    // console.log(str)
posted @ 2021-05-04 21:04  13522679763-任国强  阅读(250)  评论(0)    收藏  举报