Req #68529 [Com]: Prevent double results when using named capture groups

From: Date: Sun, 17 May 2015 06:06:12 +0000
Subject: Req #68529 [Com]: Prevent double results when using named capture groups
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192703@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68529&edit=1 ID: 68529 Comment by: danielklein at airpost dot net Reported by: gooh@php.net Summary: Prevent double results when using named capture groups Status: Open Type: Feature/Change Request Package: *Regular Expressions PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I was just about to post the same thing! I would want a flag to pass in to preg_match() and preg_match_all(), something like PREG_PREFER_NAMED_CAPTURES. Previous Comments: ------------------------------------------------------------------------ [2014-11-30 21:03:02] gooh@php.net Description: ------------ When using preg_match_all with named capture groups, the result array will contain one entry with a numeric key in addition to one entry with the name of the group. Assuming I put the named capture group there on purpose, there is no reason why I would need the numeric index. It only bloats the result array. As a user I would like to have an option that returns the results without the superfluous numeric index. Test script: --------------- <?php preg_match_all( '/This message contains (?<items>[\d]+) items/', 'This message contains 42 items', $matches ); print_r($matches); Expected result: ---------------- Array ( [0] => Array ( [0] => This message contains 42 items ) [items] => Array ( [0] => 42 ) ) Actual result: -------------- Array ( [0] => Array ( [0] => This message contains 42 items ) [items] => Array ( [0] => 42 ) [1] => Array ( [0] => 42 ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68529&edit=1

« previous php.bugs (#192703) next »