javascript 之 实现trim()

来源:互联网 发布:微信服务号域名是什么 编辑:程序博客网 时间:2024/05/04 00:45
<head><script type="text/javascript">String.prototype.trim = function() {var reExtraSpace = /^\s*(.*?)\s*$/;return this.replace(reExtraSpace,"$1");}var test = "   this is a test  ";alert("hello");alert("["+test+"]");alert("["+test.trim()+"]");</script></head><body></body>


$1:反向引用,对于分组(.*?)