//去掉左侧空格
" 武松打虎 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