whitespace - Javascript - Remove space- not breaks -
how can remove space in string, without removing breaks inside?
$new=$new.replace(/\s+/g,' '); //not working correct test. please remove space not breaks inside test. please remove space not breaks
just use / +/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"> test. please remove space not breaks inside </pre> <pre id="result"> </pre>
Comments
Post a Comment