Reputation: 2342
Trying to replace two <br />
with a single one.
Can't get it work. been trying for a couple of hours.
My code: thishtml = thishtml.replace(/(?:<br \/\>\s*){2,}/g, '<br>')
Not working.
Help will be great.
Thanks ahead.
Upvotes: 1
Views: 869
Reputation: 22820
$('br').map(function(){
($next = $(this).next()).is('br') && $next.remove();
});
If your html is not coming from the DOM:
$(thishtml).find('br').map( ... )
Upvotes: 7
Reputation: 148744
try this :
.replace(/(?:<\s*br\s*\/?\>\s*){2,}/ig, '<br/>');
example :
var a='sdf sd\
sdf\
sdf\
<br />\
<br/>\
dfbd'
result :
sdf sdsdfsdf<br/>dfbd
http://jsbin.com/OfEbaCA/6/edit
Upvotes: 1
Reputation: 32537
Try
thishtml = thishtml.replace(/(?:<br[^>]*>\s*){2,}/g, '<br>')
Upvotes: 3