【发布时间】:2021-12-19 01:55:11
【问题描述】:
如何使用 sed 或 perl 删除所有 <a href="file://???">keep this text</a> 而不是其他 <a></a> 或 </a>?
是:
<p><a class="a" href="file://any" id="b">keep this text</a>, <a href="http://example.com/abc">example.com/abc</a>, more text</p>
应该是:
<p>keep this text, <a href="http://example.com/abc">example.com/abc</a>, more text</p>
我有这样的正则表达式,但它太贪心并且删除了所有</a>
gsed -E -i 's/<a*href="file:[^>]*>(.+?)<\/a>/\1>/g' file.xhtml
【问题讨论】:
-
考虑使用更具代表性的数据集更新问题;特别是...您提到
remove all,这意味着您可能想要删除 multiple 条目,因此显示多个条目的示例将是有益的;另外,您是要删除 allfile:条目还是仅删除某些条目?