Matching multiple terms with regex
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.
精彩评论