Suppressing full pattern match in regex (preg_match())

回眸只為那壹抹淺笑 提交于 2019-12-12 11:25:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!