我正在努力寻找这个正则表达式的解决方案,这似乎是相当直接的。我需要匹配一个在另一个匹配模式之前的模式。
我需要捕捉以下“Keberos-wsfed”之后的“Mean:”:
Kerberos:
Historical:
Between 26 and 50 milliseconds: 10262
Between 50 and 100 milliseconds: 658
Between 101 and 200 milliseconds: 9406
Between 201 and 500 milliseconds: 6046
Between 501 milliseconds and 1 second: 1646
Between 1 and 5 seconds: 1399
Between 6 and 10 seconds: 13
Between 11 and 30 seconds: 34
Between 31 seconds and 1 minute: 7
Between 1 minute and 2 minutes: 1
Mean: 268, Mode: 36, Median: 123
Total: 29472
Kerberos-wsfed:
Historical:
Between 26 and 50 milliseconds: 3151
Between 50 and 100 milliseconds: 129
Between 101 and 200 milliseconds: 650
Between 201 and 500 milliseconds: 411
Between 501 milliseconds and 1 second: 171
Between 1 and 5 seconds: 119
Between 6 and 10 seconds: 4
Between 11 and 30 seconds: 6
Between 1 minute and 2 minutes: 1
Mean: 176, Mode: 33, Median: 37
Total: 4642
我可以匹配(?:Kerberos-wsfed :),我可以匹配Mean:但是我必须在Kerberos-wsfed之后找到Mean的值但是有困难。谢谢你的帮助。
答案 0 :(得分:2)
答案 1 :(得分:0)
使用捕获组:
Kerberos-wsfed:[\s\S]*Mean:\s(\d+)
Kerberos-wsfed:
与文字原样匹配[\s\S]*
允许(包括行分隔符)Mean:\s
与文字Mean
匹配,后跟空格\s
(\d+)
包含在第一个捕获组中,捕获您要查找的值。它基本上允许任意数量的数字您要查找的值(176
)将位于第一个捕获组$1
或第一个基于您的语言的捕获组。例如,在PHP中:
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
echo $matches[0][1];
// Output: 176
答案 2 :(得分:0)
尝试使用常规表达式:#Kerberos-wsfed:.+?Mean:\s+(\d+)#s
如果您以文件格式保密,则可以只使用空格或\s
代替\s+
。
值176
将位于匹配元素的第1组