Notepad++ 正则表达式查找包含子字符串的 XML 属性

Notepad++ regex find XML attribute containing a substring

我正在尝试查找 XML 标签,该标签的属性确实在其字符串中包含特定值。例如你有这个 XML:

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

在此示例中,您看到 id 中包含 'TESTING'。但是也有id没有这个的情况,像这样:

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

可以通过这个正则表达式找到:

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

需要在上面的正则表达式中进行哪些更改才能找到其 id 中包含 'TESTING' 的情况。

  • Ctrl+F
  • 查找内容:<situation xsi:type="([^"]*)" id="[^"]*TESTING[^"]*"(?:(?!</situation>).)+</situation>
  • 检查 匹配大小写
  • 检查 环绕
  • 检查 正则表达式
  • 检查 . matches newline
  • 在当前文档中查找所有内容

解释:

<situation xsi:type="           # literally
([^"]*)                         # group 1, 0 or more non "
"                               # quote
id="                            # literally
[^"]*                           # 0 or more non "
TESTING                         # literally
[^"]*                           # 0 or more non "
"                               # quote
(?:(?!</situation>).)+          # 1 or more any character, but never </situation>
</situation>                    # end tag

截图: