Reputation: 25
I have some HTML output code, example part:
<div class="header">
\n\t
<div class="header-inner">
\n\t\t
<div class="title">
Title\n\t\t
</div>
\n\t
</div>
\n
</div>
Div .title have newline and tabs before it close. It's possible delete it (replace with JS pattern)? Text random, not always "Title", and tags with the same problem can be a lot.
Need:
<div class="header">
\n\t
<div class="header-inner">
\n\t\t
<div class="title">
Title
</div>
\n\t
</div>
\n
</div>
Upvotes: 1
Views: 346
Reputation: 1725
please review this one
var x = `<div class="header">\n\t<div class="header-inner">\n\t\t<div class="title">Title\n\t\t</div>\n\t</div>\n</div>`;
var y = x.replace(/(\w+[\s]?)\s[\s]+/gi,function(a, b) {return a.trim();});
console.log(x, y);
Upvotes: 1