js正则表达式去掉空格

//去掉左侧空格
"     武松打虎    2233     ".replace(new RegExp("^\\s*","g"),"")

//去掉右侧空格
"     武松打虎    2233     ".replace(new RegExp("\\s*$","g"),"")

//去掉所有空格
"      5555     6666    ".replace(new RegExp("\\s+","g"),"");  

扩展字符串函数


 /*去掉字符串两侧空格*/
String.prototype.myTrim = function()
{
    
    
  return   this.replace(new RegExp("^\\s*|\\s*$","g"),"");   
}

 /*去掉所有空格*/
String.prototype.myTrimAll = function()
{
    
     
   return this.replace(new RegExp("\\s+","g"),"");  
}

转载 :
https://blog.csdn.net/liweibin_/article/details/8996016

猜你喜欢

转载自blog.csdn.net/u011511086/article/details/131783035
今日推荐