用正则表达式Trim js方法

//用正则表达式将前后空格 用空字符串替代。
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}

原文地址:https://www.cnblogs.com/justinsun/p/2151413.html