#50605 [Opn->Bgs]: preg_split Wrong count of matches with PREG_SPLIT_DELIM_CAPTURE

From: Date: Tue, 29 Dec 2009 13:51:57 +0000
Subject: #50605 [Opn->Bgs]: preg_split Wrong count of matches with PREG_SPLIT_DELIM_CAPTURE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146185@lists.php.net to get a copy of this message
ID: 50605 Updated by: jani@php.net Reported By: serovov at gmail dot com -Status: Open +Status: Bogus Bug Type: PCRE related Operating System: * PHP Version: 5.2.12 New Comment: To get the expected (OR) result, you need one more set of parenthesis: {(((a|b)|c))}six Then it includes all patterns.. Previous Comments: ------------------------------------------------------------------------ [2009-12-29 12:57:38] serovov at gmail dot com Description: ------------ When you use preg_split with PREG_SPLIT_DELIM_CAPTURE i have different count of matches. Reproduce code: --------------- <?php $res1 = preg_split( '{((a|b)|c)}six', '--a--b--c--', 0, PREG_SPLIT_DELIM_CAPTURE ); var_export($res1); Expected result: ---------------- array ( 0 => '--', 1 => 'a', 3 => '--', 4 => 'b', 6 => '--', 7 => 'c', 8 => '--', ) OR: array ( 0 => '--', 1 => 'a', // All patterns 2 => 'a', // First group 3 => 'a', // Second group 4 => '--', 5 => 'b', 6 => 'b', 7 => 'b', 8 => '--', 9 => 'c', // Zero group 10 => 'c', // First group 11 => '', // Second group: None-match 12 => '--', ) Actual result: -------------- array ( 0 => '--', 1 => 'a', 2 => 'a', 3 => '--', 4 => 'b', 5 => 'b', 6 => '--', 7 => 'c', 8 => '--', ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50605&edit=1

« previous php.bugs (#146185) next »