正则表达式搜索字符串多行中是否存在字符串

问题描述 投票:0回答:1

我有一个带有一堆查询字符串的 xml 文件。我需要检查每个查询中是否缺少命令。

简单地说,我可以识别不包含子字符串的字符串。这里的模式正确并且仅匹配第二行。够简单的。

aa((?<!bb).)*?dd

aa-ee-bb-cc-dd
aa-ee-cc-dd

但是当我在 xml 文件中尝试在较大的多行字符串中执行此操作时,它会捕获所有字符串,甚至包含子字符串的字符串。

目标:在 元素内部查找没有“sistats”的字符串,并且不会泄漏到下一个查询中。

这里所有 4 个查询字符串都匹配,甚至包含 sistats 的查询字符串。只有最后 3 个应该匹配。

(?s)(<search\s+id=".+?">).*?<query>((?<!sistats).)*?((?<!<\/search>).)*?<\/query>

<form>
  <search id="id1">
    <query>index=asdf
| fields asdf
| sistats count</query>
  </search>
  <search id="id2">
    <query>index=asdf
| fields asdf
| chart count</query>
  </search>
  <search id="id3">
    <query>index=asdf
| fields asdf
| sitimechart
| table asdf</query>
  </search>
  <search id="id4">
    <query>index=asdf
| table asdf</query>
  </search>
  <row>
    <panel>

https://regex101.com/r/V4ztar/1

我怎样才能只匹配最后3个?

regex splunk
1个回答
0
投票

您需要查看

mvfilter
- 一旦数据位于 Splunk 中的多值字段中,您就可以执行以下操作:

| eval missing_item_list = mvfilter(!match(full_list,"bb"))
© www.soinside.com 2019 - 2024. All rights reserved.