Reputation: 7
I have that content:
ALL EVERYTHING
I want to remove all
and get that string: ALL EVERYTHING
.
If I use that code:
var str = $("#post_wall_textarea_parent .emojionearea-editor").html(); // I can't use $("#post_wall_textarea_parent .emojionearea-editor").text(); for many reasons
str_ = str.replace(/ /g, " ");
It gives me that: ALL EVERYTHING
.
I want to remove more thant one space between two words.
How could I do to get: ALL EVERYTHING
instead of ALL EVERYTHING
. ?
Thanks.
Upvotes: 1
Views: 109
Reputation: 465
Use str.replace(/( )+/g, " ");
const str = "ALL EVERYTHING";
const result = str.replace(/( )+/g, " ");
console.log(result);
`Edited as Dimitri's Comment.
Upvotes: 1