JS 正则表达式 去字符串空格
2017-03-15 15:21
309 查看
JS 去字符串空格 总结
str为要去除空格的字符串:
去除所有空格:
去除两头空格:
去除左空格:
去除右空格:
去除空格(TimeSheet用过)
str为要去除空格的字符串:
去除所有空格:
str = str.replace(/\s+/g,"");
去除两头空格:
str = str.replace(/^\s+|\s+$/g,"");
去除左空格:
str=str.replace( /^\s*/, '');
去除右空格:
str=str.replace(/(\s*$)/g, "");
去除空格(TimeSheet用过)
arg0=arg0.replace(/\s+$|^\s+/g,"");
<script type="text/javascript"> Trim() , Ltrim() , RTrim() String.prototype.Trim = function(){ returnthis.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = function(){ returnthis.replace(/(^\s*)/g, ""); } String.prototype.RTrim = function(){ returnthis.replace(/(\s*$)/g, ""); } </script >
<input type="text" value=" 前后都是空格 " id="space"> <input type="button" value="去前后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.Trim();document.getElementById('space').select();"> <input type="button" value="去前空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();"> <input type="button" value="去后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();"> <input type="button" value="还原" onclick="javascript:document.getElementById('space').value=' 前后都是空格 ';"> <a href="http://www.yaoasnsi.com" target="_blank">访问yaosansi.com</a>
相关文章推荐
- js用正则表达式去除字符串左右空格
- js中使用正则表达式去除字符串前后空格
- 使用js的正则表达式删除字符串两边的空格
- 在JS中,使用正则表达式,用指定字符替换字符串前后空格
- js---在前端开发中,如何通过正则表达式去除字符串string首尾的空格,JavaScript正则去除首尾空格
- 用JS去掉字符串中的空格(正则表达式的应用)
- js去掉字符串中的空格---用正则表达式;
- js--打卡--12.07正则表达式 去除字符串前后空格
- 正则表达式,如果字符串中间还有连续空格的话,仅保留一个空格,即允许字符串中间有多个空格,但连续的空格数不可超过一个
- js正则表达式去空格
- 用正则表达式判断字符串是汉字还是拼音的js函数代码
- js正则表达式提取字符串中的数字
- C#使用正则表达式去除字符串中的多个不同大小的空格
- JS字符串替换函数全部替换方法 JS 正则表达式如何使用变量
- java 技巧 去除字符串中的空格、回车、换行符、制表符(正则表达式)
- js里如何将字符串转成正则表达式
- AS3的正则表达式 去除字符串首尾空格
- 获取服务器传来的数据 用JS去空格的正则表达式
- js利用正则表达式去空格
- 去除字符串中多个空格(正则表达式)