/(^\s*)|(\s*$)/g是什么意思啊?
2015-03-28 分类:javaWEB 阅读(56) 评论(0)
1 2 3 4 5 | function fTrim(str) { str=str.replace(/(^\s*)|(\s*$)/g, ""); return str; } |
Java
1 2 3 4 5 6 7 8 | stringObj.replace(rgExp, replaceText) 将stringObj中满足rgExp这个表达式的内容,使用replaceText进行替换,返回替换结果。
rgExp要求是一个正则表达式。 有关正则表达式的语法,参见<a href="http://www.yesky.com/imagesnew/software/vbscript/html/jsgrpRegExpSyntax.htm" target="_blank" rel="nofollow">http://www.yesky.com/imagesnew/software/vbscript/html/jsgrpRegExpSyntax.htm</a>
str.replace(/(^\s*)|(\s*$)/g, ""); 就是把str首尾的空格去掉。 |