Php 正则表达式以匹配字符串中的所有事件
我试图编写正则表达式来匹配下一个字符串中的所有事件类型(应该以空格字符或括号结尾)Php 正则表达式以匹配字符串中的所有事件,php,regex,Php,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 ev
(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-*
) )
我需要获取所有匹配项的数组,例如数组(“sec stunnel客户端-*”、“sec stunnel crl-*”、“sec stunnel加载-*”)
如何做到这一点?试试这个正则表达式:
(?<=eventtype=)\S*
(?您可以使用\K
而不是正向前瞻(?如果您尝试过某项服务,请在问题中添加您的尝试,包括您遇到的问题和预期的输出。如果您没有尝试过任何东西,您应该在提问之前这样做。这不是免费的编码服务。请编写一个正则表达式,搜索“eventtype=”,并在下一个“”之前进行展望。相关:这可能会起作用,但它是免费的rally不赞成回答OP根本没有努力解决问题的问题。
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-*
...
)