开发者

Matching multiple terms with regex

开发者 https://www.devze.com 2023-03-28 15:36 出处:网络
This is response to my previous thread (Matching data 开发者_如何学Cfrom file with regex) However it was matching only one keyword \"DATA\", but the file contains 20 others in the same format, but I

This is response to my previous thread (Matching data 开发者_如何学Cfrom file with regex)

However it was matching only one keyword "DATA", but the file contains 20 others in the same format, but I only want to pull out 3 specific ones including "DATA", which "STAT", "REG", "NET"

Is there anyway match these specific terms?

Thank you in advance!


Assuming this is the one you're using now:

preg_match_all('/^\s*.?"(?:DATA|STAT|REG|NET)" (\d+)\.(\d+)\s*$/m', $str, $matches);

Simply by grouping the different alternatives in a subpattern (seperated by pipes) you can easily match different values. Note that the ?: symbol in the beginning of the parantheses ignores capture for that subpattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消