|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-18 20:08 UTC] 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); ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jun 17 11:00:02 2026 UTC |
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);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) «+»