<script> var str = "<div><p> hello word. this is tom.</p><p> hello word. this is jack.</p></div>"; console.log(str.replace(/\s+/g,' '));//<div><p> hello word. this is tom.</p><p> hello word. this is jack.</p></div> </script>
var str = "<div><p> hello word. this is tom.</p><p> hello word. this is jack.</p></div>"; console.log(str.match(/\s+/) + str.replace(/\s+/g, ' '));保留最前空格+移除所有空格
var a=$("input").val(); a=a.replace(/[ ]/g,""); alert(a);
var spaceReg = "\\s+";
var str = "<div><p> hello word. this is tom.</p><p> hello word. this is jack.</p></div>";
console.log(str.replace(/\s+/g,' '));//<div><p> hello word. this is tom.</p><p> hello word. this is jack.</p></div>
</script>
console.log(str.match(/\s+/) + str.replace(/\s+/g, ' '));保留最前空格+移除所有空格
var a=$("input").val();
a=a.replace(/[ ]/g,"");
alert(a);