|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67520 preg_match should capture always all parentheses
Submitted: 2014-06-26 07:03 UTC Modified: 2014-07-01 06:55 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: hejdav at centrum dot cz Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: hejdav at centrum dot cz
New email:
PHP Version: OS:


 [2014-06-26 07:03 UTC] hejdav at centrum dot cz
When preg_match() is called, I'm expecting that $matches will contain always one index per one capturing group. But when there is capturing group at the end of the pattern and it is not matched, $matches does not contain its index.

Test script:
$regexp = '/foo( bar)?/';
preg_match($regexp, 'foo', $matches);

Expected result:
Array (
  [0] => foo
  [1] =>

Actual result:
Array (
  [0] => foo


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-01 06:55 UTC]
-Status: Open +Status: Not a bug
 [2014-07-01 06:55 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

preg_match_all() is probably what can fulfill your expectation.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 05:01:33 2024 UTC