鉴于这个例子,案文如下:
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ABB</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="FM"/>
...lines...
...........
</abr:rules>
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ADE</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="CM"/>
...lines...
...........
</abr:rules> (end of group)我想找到并删除从<abr:rules>到</abr:rules>的所有内容,条件是subapplication IS NOT "CM"。组织和应用程序是相同的,<abr:code>是任何字符串。
到目前为止我尝试的是
<abr:rules>\n<abr:ruleTypeDefinition>\n<abr:code>[a-zA-Z0-9]{3,}<\/abr:code>\n<abr:ownership>\n<.*"(FM|PSD|SSC)"\/>\n(?s).*?\n<\/abr:rules>\n这是可行的,但只因为我知道其他子应用程序的名称。
有办法只用Regex吗?
发布于 2018-04-13 15:05:15
尝试以下查找和替换:
查找:
<abr:rules>((?!subapplication=).)*subapplication="(?!CM")[^"]+"((?!</abr:rules>).)*</abr:rules>替换:
(empty string)
注意:只有在允许Notepad++中的点匹配换行符时,上面的模式才能工作。如果您不想这样做,那么您可以使用[\S\s]而不是点。
发布于 2018-04-13 16:08:39
您不应该将regex用于xml,您可以在这里阅读为什么:https://stackoverflow.com/a/1732454/3763374
相反,您可以使用像Xpath这样的解析器。
https://stackoverflow.com/questions/49819834
复制相似问题