replace multiple <br> in javascript replace with single <br>?
html, javascript, regex
Solution
Try this
var str="<p>fhgfhgfhgfh</p><br><br><p>ghgfhfgh</p><br><br><p>";
var n=str.replace(/<br><br>/g,"<br>");
console.log(n);
Working DEMO
Edit: Above works for 2 `br` tags, code below should take care of any number of br tags.
var n = str.replace(/(<br>)+/g, '<br>');
Working DEMO
where `/.../` denotes a regular expression, `(<br>)` denotes `<br>` tag, and `+` denotes one or more occurrence of the previous expression and finally `g` is for global replacement.
Problem
I want to replace the multiple `<br>` tags with single `<br>` in a text. my text like, ``` <p>fhgfhgfhgfh</p> <br><br> <p>ghgfhfgh</p> <br><br> <p>fghfghfgh</p> <br><br> <p>fghfghfgh</p> <br><br> <p>fghfgh</p> <br><br> ``` How i replace the multiple `<br>` with single `<br>`?.