|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-12-29 12:57 UTC] 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 => '--',
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 12:00:02 2025 UTC |
To get the expected (OR) result, you need one more set of parenthesis: {(((a|b)|c))}six Then it includes all patterns..