去除段首段尾的 和全角的空格的正则
更新时间:2009年08月09日 00:29:25 作者:
去除段首段尾的 和全角的空格的正则,代码看起来不如之前的版本,简单,需要更了解正则的特殊字符。
<script language="javascript">
<!--
String.prototype.trim = function(){
return this.replace(/^( |[\s ])+|( |[\s ])+$/g, "" );
}
alert("---"+ " this is a test kwgkwg ".trim() + "---");
/ --></script>
1、去段首段尾的空格(包括半角的空格代码 和全角的空格" ")
2、段中的空格(包括半角的空格代码 和全角的空格" ")给予保留!
<!--
String.prototype.trim = function(){
return this.replace(/^( |[\s ])+|( |[\s ])+$/g, "" );
}
alert("---"+ " this is a test kwgkwg ".trim() + "---");
/ --></script>
1、去段首段尾的空格(包括半角的空格代码 和全角的空格" ")
2、段中的空格(包括半角的空格代码 和全角的空格" ")给予保留!
相关文章
js中exec、test、match、search、replace、split用法
exec、test、match、search、replace、split在JS中用的很频繁,在网上看到对这些方法的总结,就转过来了,作个记录2012-08-08


最新评论