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

From: Date: Mon, 03 Oct 2016 20:22:31 +0000
Subject: Bug #73236 [Nab]: preg_match subcaptures are overwritten in repeating patterns
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204430@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
 User updated by:    kael dot shipman at gmail dot com
 Reported by:        kael dot shipman at gmail dot com
 Summary:            preg_match subcaptures are overwritten in repeating
                     patterns
 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:

Oops, sorry for making extra work, and thanks for the clarification!


Previous Comments:
------------------------------------------------------------------------
[2016-10-03 20:15:19] bwoebi@php.net

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.

------------------------------------------------------------------------
[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


Thread (3 messages)

« previous php.bugs (#204430) next »