如何用正则表达式替换多个< br/>带有一个< br/>标签标签? [英] How to Regex-replace multiple <br /> tags with one <br /> tag?
本文介绍了如何用正则表达式替换多个< br/>带有一个< br/>标签标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望<br /><br />
变成<br />
使用正则表达式的模式是什么?
注意:<br />
标签可以连续出现2次以上.
解决方案
您可以使用s/(<br \/>)+/<br \/>/
,但是如果您尝试在HTML上使用正则表达式,则可能做错了事.>
如果您有不同的休息时间,可以使用一种更健壮的模式:
/(<br\ ?\/?>)+/
这也将捕获<br/>
和<br>
,在某些情况下可能会有用.
I want <br /><br />
to turn into <br />
What's the pattern for this with regex?
Note: The <br />
tags can occur more than 2 times in a row.
解决方案
You could use s/(<br \/>)+/<br \/>/
, but if you are trying to use regex on HTML you are likely doing something wrong.
Edit: A slightly more robust pattern you could use if you have mixed breaks:
/(<br\ ?\/?>)+/
This will catch <br/>
and <br>
as well, which might be useful in certain cases.
这篇关于如何用正则表达式替换多个< br/>带有一个< br/>标签标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文