比较简单实用的使用正则三种版本的js去空格处理方法_javascript技巧
程序员文章站
2022-03-17 16:55:52
...
分别去字符串前后,左边,右边空格
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,"")}
String.prototype.ltrim = function(){ return this.replace(/^\s+/g,"")}
String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")}
复制代码 代码如下:
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,"")}
String.prototype.ltrim = function(){ return this.replace(/^\s+/g,"")}
String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")}