我有一个包含数千个不同事件和消息类型的日志,用于运行查询以查找和替换某些特定数据,例如这里是一个示例 事件1
"eventID": "Ar39084",
"data2": "http://sfa.stanly.local:8787/nices-uri/msa/PRAS- TAM80/root/BLA_Notification::LINKDOWN-ISA_NA-Ar39084~2F538
"data3": "[excm][132.19][78.65][68493435][Ar39084]"
"data4": "AGV.SDA.Ar39084"
事件2
"eventID": "Ar39079",
"data2": "http://sfa.stanly.local:8787/nices-uri/msa/PRAS-TAM80/root/BLA_Notification::LINKDOWN-ISA_NA-Ar39079~2F538
"data3": "[excm][132.19][78.65][68493435][Ar39079]"
"data4": "AGV.SDA.Ar39079"
所以我想要的是在我的记事本++中搜索适用于第1组的所有内容,这是我所拥有的查询,
"eventID": "(.*?)",
因此,我希望所有与eventID(Ar39084和Ar39079)组1内容匹配的内容,以便它与data2,data 3,data 4等等相匹配,并且此查询也可以与event 2,event 3等等相匹配。
这样我就可以在日志Ar39084 Ar39079 Ar394354中替换任何与查询匹配的字符串
因此,在应用替换后,我的日志如下所示:
事件1
"eventID": "${variable}",
"data2": "http://sfa.stanly.local:8787/nices-uri/msa/PRAS- TAM80/root/BLA_Notification::LINKDOWN-ISA_NA-${variable}~2F538
"data3": "[excm][132.19][78.65][68493435][${variable}]"
"data4": "AGV.SDA.${variable}"
事件2
"eventID": "${variable}",
"data2": "http://sfa.stanly.local:8787/nices-uri/msa/PRAS-TAM80/root/BLA_Notification::LINKDOWN-ISA_NA-${variable}~2F538
"data3": "[excm][132.19][78.65][68493435][${variable}]"
"data4": "AGV.SDA.${variable}"
答案 0 :(得分:0)
This should help:
I did a grouping on (Ar\d+)
to match Ar
followed by \d+
for any number of digits.
UPDATE:
Based on the potential for other events starting with something other than simply Ar
, the find regex grouping changes to:
([a-zA-Z]{2}\d{5,}) // 2 characters followed by 5 (or more) digits.
That will match events named:
Jm37908
Za94025
Sw02834
Pt012345678 (should there ever be more than 5 digits)
Plus others with similar formats
You can try the regex here.
答案 1 :(得分:0)
尝试一下:
查找内容:"eventID":\s*"\K(\w+)("[\s\S]*?)(?=\b\1\b)|\G(\w++)(?=(?:[^"](?!\3))*"\s+(?:"eventID"|\z))|\G(\w++)([\s\S]*?)(?=\b\4\b)
替换:\${variable}\2\5
您有一个演示here。
它应该与包含字母,数字和下划线的任何标识符一起使用,只要该标识符周围有一些单词边界(这似乎是您的情况)