【发布时间】:2019-06-13 14:27:16
【问题描述】:
我正在使用 Notepad++ 中的正则表达式搜索功能在数百个文件中查找匹配项。
我的目标是在每个中找到一个父/子组合。我不太关心具体选择了什么(父母和孩子或只是孩子)。我只想知道父母是否包含特定的孩子。
我想找到一个也有一个子元素的父元素。
它应该找到的示例(因为其中一个子元素是 a ):
<description>
<otherstuff>
</otherstuff>
<something>
</something>
<description>
</description>
<otherstuff>
</otherstuff>
</description>
不应找到的示例:
<description>
<otherstuff>
</otherstuff>
<something>
</something>
<notadescription>
</notadescription>
<otherstuff>
</otherstuff>
<description>
每个都可能有其他孩子和子孩子。它们也可能在同一个文档中。
如果我搜索这个:
<description>(.*)<description>(.*)</description>
它选择了太多,因为当我只希望它为第二个部分选择子级时,它会选择另一个顶层。
【问题讨论】: