我正在尝试替换任何 <br />
在 </h2>
之后出现的标签标签。这是我目前所拥有的:
Text = Text.replace(new RegExp("</h2>(\<br \/\>.+)(.+?)", "g"), '</h2>$2');
好像不行,谁能帮忙? (未找到匹配项)。
测试用例:
<h2>Testing</h2><br /><br /><br />Text
收件人:
<h2>Testing</h2>Text
最佳答案
这比您想象的要简单:
Text = Text.replace(new RegExp("</h2>(\<br \/\>)*", "g"), "</h2>");
关于Javascript 正则表达式替换所有 <br/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825825/