问题
The returned matches array contains as the first element the entire string matched, followed by the captured groups.
I can't locate an option on php.net to just return the captured groups?
Is there one?
回答1:
No, it is standard for 0
to contain the entire matched string.
If it were of a concern, you could always unset($matches[0])
(which won't affect the keys) or array_slice($matches, 1)
.
来源:https://stackoverflow.com/questions/7949436/suppressing-full-pattern-match-in-regex-preg-match