正则表达式匹配类似单词后的字符串

问题描述 投票:3回答:2

我试图解析下面的日志文件;但是,在所有“Step = Number”之后,我有点想弄清楚如何匹配结果。

Step = 10,Step = 11,Step = 12,Step = 13,Step = 14,Step = 15,Step = 16,Step = 18,Step = 17,Step = 20,Step = 19,Step = 25,Step = 21,Step = 26,Step = 28,Step = 24,Step = 22,Step = 23,Step = 27,Step = 30,Step = 29,Step = 35,Step = 34,Step = 32,Step = 31, Step = 38,Step = 37,Step = 36,Step = 50,Step = 45,Step = 48,Step = 41,Step = 52,Step = 42,Step = 57,Step = 65,Step = 61,Step = 62,Step = 64,Step = 54,Step = 53,Step = 59,Step = 63,Step = 84,Step = 71,SelectedAuthenticationIdentityStores = paddedvalue,NetworkDeviceName = exampledevice,NetworkDeviceGroups = Update Source:All Sources:ACS,NetworkDeviceGroups =设备类型:所有设备类型:无线,NetworkDeviceGroups =位置:所有位置,ServiceSelectionMatchedRule = Rule-1,IdentityPolicyMatchedRule =默认

在以下组合之后我考虑匹配:\ d \ s \,\ s

理想的目标是匹配以下内容:

SelectedAuthenticationIdentityStores = paddedvalue,NetworkDeviceName = exampledevice,NetworkDeviceGroups = Update Source:All Sources:ACS,NetworkDeviceGroups = Device Type:All Device Types:Wireless,NetworkDeviceGroups = Location:All Locations,ServiceSelectionMatchedRule = Rule-1,IdentityPolicyMatchedRule = Default

我尝试了以下正则表达式:\d\s\\,\s(.*)但是在第一步= Number之后匹配所有内容(步骤= 10)

php regex pcre
2个回答
1
投票

您可以在现有模式的开头使用另一个。*来贪婪地消耗除最后一个匹配之外的所有匹配:

.*\d\s,\s(.*)

但是:Kua zxsw指出

或者,您可以使用正向lookbehind模式来确保匹配前面有一个https://regex101.com/r/Oc7jUK/1和一个负前瞻模式,以确保后面没有更多的\d\s,\s

\d\s,\s

但是:Kua zxsw指出


0
投票

为什么不使用像(?<=\d\s,\s)(?!.*\d\s,\s).* https://regex101.com/r/Oc7jUK/2之类的所有SelectedAuthenticationIdentityStores匹配的正则表达式

SelectedAuthenticationIdentityStores.*
© www.soinside.com 2019 - 2024. All rights reserved.