我试图编写RegEX来匹配下一个字符串中的所有事件类型(应该以空白字符或括号结束。
(STUNNEL-SECURITY AND NOT (
eventtype=sec-stunnel-client-*
OR eventtype=sec-stunnel-crl-*
OR eventtype=sec-stunnel-loaded-*
OR eventtype=sec-stunnel-loading-*
OR eventtype=sec-stunnel-no-*
OR eventtype=sec-stunnel-openssl-*
OR eventtype=sec-stunnel-sconnect-*
OR eventtype=sec-stunnel-server-*
OR eventtype=sec-stunnel-service-*
OR eventtype=sec-stunnel-session-*
OR eventtype=sec-stunnel-socket-*
OR eventtype=sec-stunnel-ssl-*
OR eventtype=sec-stunnel-stats-*
OR eventtype=sec-stunnel-threading-*
OR eventtype=sec-stunnel-timeout-*
OR eventtype=sec-stunnel-various-*
) )
我需要获得所有比赛的数组,例如。 array("sec-stunnel-client-*", "sec-stunnel-crl-*", "sec-stunnel-loaded-*"...)
。
应如何做到这一点?
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以使用\K
代替积极前瞻(?<=)
更少的步骤。
正则表达式:eventtype=\K\S+
详细说明:
\K
重置报告的匹配的起点\S+
匹配一次和无限次之间的任何非空格字符PHP代码:
preg_match_all("~eventtype=\K\S+~", $str, $matches);
输出:
Array
(
[0] => sec-stunnel-client-*
[1] => sec-stunnel-crl-*
[2] => sec-stunnel-loaded-*
[3] => sec-stunnel-loading-*
[4] => sec-stunnel-no-*
...
)