简体   繁体   English

Notepad++ 正则表达式查找不包含某些子 XML 标签的 XML 标签

[英]Notepad++ regex find XML tags which does not contain certain child XML tags

I am trying to look in notepad++ for XML tags which does not contain a certain child tag.我正在尝试在记事本++中查找不包含某个子标签的 XML 标签。 For example you have a lot of XML tags like this:例如,您有很多 XML 标签,如下所示:

<situation xsi:type="management" id="...">
        ....
        <mobility>
            ...
        </mobility>
        .....
</situation>

And some of them do not contain the mobility tag like this:其中一些不包含这样的移动标签:

<situation xsi:type="management" id="...">
        ....
</situation>

For the one with the mobility tag I know that you can search it up when you create a regex like this:对于带有移动标签的人,我知道您可以在创建这样的正则表达式时对其进行搜索:

<situation xsi:type="management"(?:(?!</situation>).)+<mobility>([^\"]*)</mobility>

What changes do need to be made with the regex above to search for situations without the mobility child tag?需要对上面的正则表达式进行哪些更改才能搜索没有移动子标签的情况?

Make the <mobility> tag optional:使<mobility>标记可选:

<situation xsi:type="management"(?:(?!</situation>).)+(?:<mobility>([^\"]*?)</mobility>)?

If you want to match <situation> tag that doesn't contain <mobility> tag, use:如果要匹配不包含<mobility>标记的<situation>标记,请使用:

<situation xsi:type="management"(?:(?!</situation>)(?!<mobility>).)+</situation>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM