我尝试测试正则表达式的捕获组和非捕获组的性能。
顺便说一句,捕获组和非捕获组之间的差异非常微小。
这个结果正常吗?
[root@Sensor ~]# ll -h sample.log
-rw-r--r-- 1 root root 21M Oct 20 23:01 sample.log
[root@Sensor ~]# time grep -ciP '(get|post).*' sample.log
20000
real 0m0.083s
user 0m0.070s
sys 0m0.010s
[root@Sensor ~]# time grep -ciP '(?:get|post).*' sample.log
20000
real 0m0.083s
user 0m0.077s
sys 0m0.004s
.*
,因为它总是匹配的,而且你并没有捕获它。 - Andy Lester