|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-12-30 23:54 UTC] cmb@php.net
-Package: Feature/Change Request
+Package: PCRE related
[2019-03-18 16:24 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
[2019-03-18 16:24 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
Description: ------------ preg_grep should capture subpatterns. Currently it doesn't have the ability to do this. Reproduce code: --------------- array preg_grep ( string pattern, array input [, int flags] ) Expected result: ---------------- The return array would return a two dimensional array if you set a flag like PREG_GREP_CAPTURE. $array[n][0] would be the fully captured string and each additional index in that dimension would return the subpattern matches. Example: <?php $arrInput = array('5741234-5671','5741235','5741236-432'); $arrMatches = preg_grep('/([2-9][0-9]{6,15})(?:\-([0-9]{2,6}))?/', $arrInput, PREG_GREP_CAPTURE); ?> Content of $arrMatches: $arrMatches[0][0] = '5741234-5671' $arrMatches[0][1] = '5741234' $arrMatches[0][2] = '5671' $arrMatches[1][0] = '5741235' $arrMatches[2][0] = '5741236-432' $arrMatches[2][1] = '5741236' $arrMatches[2][2] = '432' Actual result: -------------- array preg_grep ( string pattern, array input [, int flags] )