正则表达式去除字符串左右空格函数 调用方法是,str.Trim();

时间:2024-01-17 12:05:32

正则表达式去除字符串左右空格函数 调用方法是,str.Trim();
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, "");
}