php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47653 Error in documentation for preg_match_all
Submitted: 2009-03-13 21:01 UTC Modified: 2009-03-14 02:37 UTC
From: cloudyovercuba at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Ubuntu Linux
Private report: No CVE-ID: None
 [2009-03-13 21:01 UTC] cloudyovercuba at gmail dot com
Description:
------------
In the documentation for preg_match_all at http://www.php.net/preg_match_all , example #3 shows that a example regex for named subpatterns is this:

/(?<name>\w+): (?<digit>\d+)/

This does not work, and returns an error.  The proper regex would be this:

/(?P<name>\w+): (?P<digit>\d+)/


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-13 23:15 UTC] felipe@php.net
The example is correct, it just requires PCRE 7.0, which is bundled with PHP5.2.2+.

$ sapi/cli/php  -r 'preg_match("/(?<name>\w+): (?<digit>\d+)/", "foo: 111", $m);print_r($m);'
Array
(
    [0] => foo: 111
    [name] => foo
    [1] => foo
    [digit] => 111
    [2] => 111
)

 [2009-03-14 02:37 UTC] cloudyovercuba at gmail dot com
Ok.  Perhaps you should make note of that in the documentation?
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 18:00:02 2026 UTC