Bug #73236 [Opn->Nab]: preg_match subcaptures are overwritten in repeating patterns

From: Date: Mon, 03 Oct 2016 20:15:21 +0000
Subject: Bug #73236 [Opn->Nab]: preg_match subcaptures are overwritten in repeating patterns
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204429@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73236&edit=1 ID: 73236 Updated by: bwoebi@php.net Reported by: kael dot shipman at gmail dot com Summary: preg_match subcaptures are overwritten in repeating patterns -Status: Open +Status: Not a bug Type: Bug Package: PCRE related Operating System: Ubuntu Studio Linux 16.04.1 PHP Version: 7.0.11 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php As per http://www.pcre.org/pcre.txt (the documentation of the underlying library): If a capturing subpattern is matched repeatedly, it is the last portion of the string that it matched that is returned. this is expected behavior. Previous Comments: ------------------------------------------------------------------------ [2016-10-03 18:19:34] kael dot shipman at gmail dot com Description: ------------ It appears as though when a subcapture is contained within a repeating pattern, the value is overwritten by subsequent matches, leaving only the last captured value in the $matches array, rather than all matched values. Test script: --------------- preg_match( '/^([^<]+)(?:<([^>]+)>)*$/', 'main<subkey><nothersub><onemore>', $keys ); var_dump($keys); Expected result: ---------------- array( 'main<subkey><nothersub><onemore>', 'main', 'subkey', 'nothersub', 'onemore' ) Actual result: -------------- array( 'main<subkey><nothersub><onemore>', 'main', 'onemore' ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73236&edit=1

« previous php.bugs (#204429) next »