gpt4 book ai didi

javascript - 从字符串中删除多余的

转载 作者:行者123 更新时间:2023-11-30 08:47:44 34 4
gpt4 key购买 nike

我想删除不必要的字符串:<br> , <br/><br />来自一个字符串,可能包含许多行。示例:

This is a string with <br><br/> many <br/><br> newlines. <br><br><br /><br> But it's ok <br> to have one!

我希望它变成这样:

This is a string with <br> many <br> newlines. <br> But it's ok <br> to have one!

最佳答案

你可以做到

str = str.replace(/<\/?br\s*\/?>\s*(<\/?br\s*\/?>)+/ig, '<br>');

关于javascript - 从字符串中删除多余的 <br>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20569140/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com