Javascript - 删除空格 - 而不是中断
Javascript - Remove space- not breaks
如何在不删除内部分隔符的情况下删除字符串中的空格?
$new=$new.replace(/'s+/g,' '); //not working correct
this is a test.
please remove only the
Space not
the breaks inside
this is a test.
please remove only the
Space not
the breaks
只需使用 / +/g
:
$new = document.getElementById('content').innerHTML;
$new = $new.replace(/ +/g,' ');
// or $new = $new.replace(/('s(?='s))+/g,'');
document.getElementById('result').innerHTML = $new;
<pre id="content">
this is a test.
please remove only the
Space not
the breaks inside
</pre>
<pre id="result">
</pre>
$new = $new.split(/ +/).join(' ');
相关文章:
- 我如何找到一个句子中的所有空格并替换忽略它们
- Regex代码只允许一个空格
- Javascript,有没有一种方法可以将数组写成没有逗号或空格的单个文本字符串
- 拆分文本以每隔n个字符添加一行新行,并注意空格
- 用空格替换下划线PHP
- 高亮显示与数组字符串一起使用时文本插件中断
- 如何为jQuery屏蔽输入插件创建一个允许字母数字、空格和重音字符的掩码
- 当没有文本输入聚焦时检测空格键按下
- 一个密码测试程序,如果存在空格,它会提醒用户
- AngularJS ui路由器html5模式中断路由
- 在谷歌应用程序脚本中转换为空格的制表符
- 如何将字符串拆分为字符,但在javascript中保留空格
- Jquery:如何获取所选选项全文(带空格)
- javascript在其中设置空格时会中断
- jQuery animate 会中断空格键滚动
- 删除 JavaScript 中的非中断空格
- 如何防止带有空格的JavaScript在WordPress中中断
- Javascript 显示复选框值与值中的空格中断
- 中断和非中断空格ascii字符之间的区别
- Javascript - 删除空格 - 而不是中断