将两个 BR 替换为单个 JQuQuestion

replace two br with single one jquery

本文关键字:替换 单个 JQuQuestion BR 两个      更新时间:2023-09-26

试图用一个替换两个<br />
无法让它工作。已经尝试了几个小时。

我的代码:thishtml = thishtml.replace(/(?:<br '/'>'s*){2,}/g, '<br>')

不工作。
帮助会很棒。

谢谢。

$('br').map(function(){
  ($next = $(this).next()).is('br') && $next.remove();
});

如果您的 html 不是来自 DOM:

$(thishtml).find('br').map( ... )

试试

thishtml = thishtml.replace(/(?:<br[^>]*>'s*){2,}/g, '<br>')

试试这个:

.replace(/(?:<'s*br's*'/?'>'s*){2,}/ig, '<br/>');

例:

var a='sdf sd'
sdf'
sdf'
<br    />'
    <br/>'
  dfbd'

结果:

sdf sdsdfsdf<br/>dfbd

http://jsbin.com/OfEbaCA/6/edit

试试这个:

.replace(/('<br['s]*'/'>){2,}/g, '<br/>')