我需要帮助制作一个正则表达式,以删除两个HTML标记之间的"/>"。
<!-- The line could look like this -->
<td align=right valign=bottom nowrap><div>January 24, 2013 /></div></td>
<!-- Or this -->
<div>Is this system supported? /></div>
<!-- Even this -->
<span>This is a span tag /></div>
<!-- It could look like any of these but I do not want /> removed -->
<img src="example.com/example.jpg"/></img>
<img src="example.com/example.jpg"/>
<img src="example.com/example.jpg"/></img>
<div id="example"><img src="example.com/example.jpg"/></div>
(是的,我知道img标签没有相应的闭合标签。我正在动态编辑许多我没有创建的页面;这不是我的标记。)
以下是我使用Perl想出的正则表达式:
s|(<.*?>(?!<img).*?)(\s*/>)(?!</img>)(</.*?>)|$1$3|gi;
有没有更有效率或更快的正则表达式?
将正则表达式应用于上述示例后,以下是结果:
<!-- The line could look like this -->
<td align=right valign=bottom nowrap><div>January 24, 2013></div></td>
<!-- Or this -->
<div>Is this system supported?></div>
<!-- Even this -->
<span>This is a span tag></div>
<!-- It could look like any of these but I do not want /> removed -->
<img src="example.com/example.jpg"/></img>
<img src="example.com/example.jpg"/>
<img src="example.com/example.jpg"/></img>
<div id="example"><img src="example.com/example.jpg"/></div>