去除段首段尾的 和全角的空格的正则

(编辑:jimmy 日期: 2024/9/23 浏览:2)

<script language="javascript">
<!--
String.prototype.trim = function(){
return this.replace(/^(&nbsp;|[\s ])+|(&nbsp;|[\s ])+$/g, "" );
}
alert("---"+ " &nbsp; &nbsp;this is a test kwgkwg  &nbsp; ".trim() + "---");
/ --></script>
1、去段首段尾的空格(包括半角的空格代码&nbsp;和全角的空格" ")
2、段中的空格(包括半角的空格代码&nbsp;和全角的空格" ")给予保留!