Req #40107 [Opn->Wfx]: preg_grep should capture subpatterns
| From: | nikic@php.net | Date: | Mon, 18 Mar 2019 16:24:15 +0000 |
| Subject: | Req #40107 [Opn->Wfx]: preg_grep should capture subpatterns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220057@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=40107&edit=1
ID: 40107
Updated by: nikic@php.net
Reported by: mattsch at gmail dot com
Summary: preg_grep should capture subpatterns
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: PCRE related
Operating System: *
PHP Version: 5.2.0
Block user comment: N
Private report: N
New Comment:
Marking this as won't fix. preg_grep() is a simple filtering functionality -- to capture
subpatterns, you can use preg_match() inside a foreach loop.
Previous Comments:
------------------------------------------------------------------------
[2007-01-12 00:28:36] mattsch at gmail dot com
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] )
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=40107&edit=1