php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72704 mb_ereg & mb_ereg_search do not return named captures
Submitted: 2016-07-29 04:17 UTC Modified: 2018-09-19 06:28 UTC
From: ju1ius at laposte dot net Assigned: nikic (profile)
Status: Closed Package: mbstring related
PHP Version: 5.6.24 OS: Debian Sid
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ju1ius at laposte dot net
New email:
PHP Version: OS:

 

 [2016-07-29 04:17 UTC] ju1ius at laposte dot net
Description:
------------
`mb_ereg`, `mb_ereg_search_regs` & `mb_ereg_search_getregs` return only numbered capturing groups, but they should return both numbered and named capturing groups.

Test script:
---------------
mb_regex_encoding("UTF-8");

mb_ereg('(?<wsp>\s*)(?<word>\w+)', '  中国', $m);
var_dump($m);

mb_ereg_search_init('  中国?');
mb_ereg_search('(?<wsp>\s*)(?<word>\w+)(?<punct>[?!])');
var_dump(mb_ereg_search_getregs());

Expected result:
----------------
array(5) {
  [0]=>
  string(8) "  中国"
  [1]=>
  string(2) "  "
  [2]=>
  string(6) "中国"
  ["wsp"]=>
  string(2) "  "
  ["word"]=>
  string(6) "中国"
}

array(7) {
  [0]=>
  string(11) "  中国?"
  [1]=>
  string(2) "  "
  [2]=>
  string(6) "中国"
  [3]=>
  string(3) "?"
  ["punct"]=>
  string(3) "?"
  ["wsp"]=>
  string(2) "  "
  ["word"]=>
  string(6) "中国"
}

Actual result:
--------------
array(3) {
  [0]=>
  string(8) "  中国"
  [1]=>
  string(2) "  "
  [2]=>
  string(6) "中国"
}

array(4) {
  [0]=>
  string(11) "  中国?"
  [1]=>
  string(2) "  "
  [2]=>
  string(6) "中国"
  [3]=>
  string(3) "?"
}

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-19 06:28 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2018-09-19 06:28 UTC] nikic@php.net
This has been implemented in PHP 7.3 (by yourself ^^) as part of https://github.com/php/php-src/pull/2044, so I'm closing this issue.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 23:01:33 2025 UTC