#46904 [Opn]: preg_match() example #4 is wrong
| From: | rquadling@php.net | Date: | Fri, 19 Dec 2008 10:05:35 +0000 |
| Subject: | #46904 [Opn]: preg_match() example #4 is wrong | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1648@lists.php.net to get a copy of this message | ||
ID: 46904
Updated by: rquadling@php.net
Reported By: joe at digg dot com
Status: Open
Bug Type: Documentation problem
Operating System: Debian GNU/Linux
PHP Version: Irrelevant
New Comment:
I'm not so sure.
Using RegexBuddy to explain the different Regexs ...
There seems to be no difference between the 2 forms.
(?<name>\w+): (?<digit>\d+)
Options: case insensitive; ^ and $ match at line breaks
Match the regular expression below and capture its match into
backreference with name ânameâ «(?<name>\w+)»
Match a single character that is a âword characterâ (letters,
digits, etc.) «\w+»
Between one and unlimited times, as many times as possible,
giving back as needed (greedy) «+»
Match the characters â: â literally «: »
Match the regular expression below and capture its match into
backreference with name âdigitâ «(?<digit>\d+)»
Match a single digit 0..9 «\d+»
Between one and unlimited times, as many times as possible,
giving back as needed (greedy) «+»
(?P<name>\w+): (?P<digit>\d+)
Options: case insensitive; ^ and $ match at line breaks
Match the regular expression below and capture its match into
backreference with name ânameâ «(?P<name>\w+)»
Match a single character that is a âword characterâ (letters,
digits, etc.) «\w+»
Between one and unlimited times, as many times as possible,
giving back as needed (greedy) «+»
Match the characters â: â literally «: »
Match the regular expression below and capture its match into
backreference with name âdigitâ «(?P<digit>\d+)»
Match a single digit 0..9 «\d+»
Between one and unlimited times, as many times as possible,
giving back as needed (greedy) «+»
Previous Comments:
------------------------------------------------------------------------
[2008-12-18 20:21:24] tobias382 at gmail dot com
Patch for /phpdoc/en/reference/pcre/functions/preg-match.xml:
278c278
< preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
---
> preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
------------------------------------------------------------------------
[2008-12-18 20:08:21] joe at digg dot com
Description:
------------
On http://us.php.net/preg_match example #4 (Using named
subpattern) is
wrong. It shows:
<?php
$str = 'foobar: 2008';
preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
print_r($matches);
?>
The proper syntax for named expressions is (?P<foo>).
Expected result:
----------------
<?php
$str = 'foobar: 2008';
preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
print_r($matches);
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46904&edit=1