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

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -