使用正则表达式删除段落开头和结尾的换行符

Remove Breaks from start and end of the paragraph using Regular expression

本文关键字:结尾 换行符 开头 段落 正则表达式 删除      更新时间:2023-11-08

我的html片段如下


<B>Summary:</B><BR><BR><BR><BR><BR>
<P><BR><SPAN style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; LETTER-SPACING: normal; DISPLAY: inline !important; FONT: 13px Verdana, Arial, sans-serif; WHITE-SPACE: normal; ORPHANS: 2; FLOAT: none; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">Web developer can also use Regular Expression in JavaScript. Now I describe some simple examples of using Regular Expression in JavaScript.</SPAN></P><BR>
<P><BR><A href="http://www.yahoo.com">www.yahoo.com</A></P><BR>
<P><BR><A href="http://www.orkut.com">www.orkut.com</A></P><BR><BR>

I want to remove all the <BR> tags between </B> and <P> tags(</B><BR><BR><BR><BR><BR> <P>)

如何使用javascript正则表达式来实现这一点。

如果正好有5:

var str = "<B>...";
str = str.replace(/(<BR>){5}/, '');