简体   繁体   中英

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

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

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

I am getting an output like this '217Z2800343645 25.00'

Heres a snippet. Dk if it's what you're looking for..

 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; )

https://jsfiddle.net/agfwo8hu/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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