From: mattsch at gmail dot com
Operating system: *
PHP version: 5.2.0
PHP Bug Type: Feature/Change Request
Bug description: preg_grep should capture subpatterns
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 bug report at http://bugs.php.net/?id=40107&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=40107&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=40107&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=40107&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40107&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=40107&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40107&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40107&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40107&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40107&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40107&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=40107&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=40107&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40107&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40107&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40107&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40107&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40107&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40107&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40107&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40107&r=mysqlcfg