简体   繁体   English

如何用空格替换字符串中的所有特殊字符

[英]How to replace all special characters in a string with space

I am trying to replace all the occurrences of @ in a string '217Z2800343645@@@@@@@25.00' with space using JavaScript regex expression 我正在尝试使用JavaScript正则表达式用空格替换字符串'217Z2800343645 @@@@@@@@@ 25.00'中所有@出现的情况

var addendaSpace = '217Z2800343645@@@@@@@25.00'

addendaSpace = addendaSpace.replace(/@/g,' ');

I am getting an output like this '217Z2800343645 25.00' 我得到这样的输出'217Z2800343645 25.00'

Heres a snippet. 这是一个摘要。 Dk if it's what you're looking for.. Dk,如果您正在寻找..

 var ad = '217Z2800343645@@@@@@@25.00' var ada = ad.replace(/@/g, " ") console.log(ada) 

html ignores mutlible spaces either use <pre></pre> tag to preserve spaces or use nonbreakablespaces ( &nbsp; ) html忽略可变空间,或者使用<pre></pre>标记保留空间或使用不可破坏的空间( &nbsp;

https://jsfiddle.net/agfwo8hu/ https://jsfiddle.net/agfwo8hu/

<pre>hello   test</pre>
<p>hello &nbsp;&nbsp;&nbsp;test</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM