From 740a7698afb0cfe9a8652b305b51a0e93a4afab3 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 17 Dec 2009 12:28:26 +0000 Subject: [PATCH] Emphasize the use of ?P<> for named sub-patterns instead of the backwards incompatible ?<>. Fixes bug #50306 - refs bug #46904 git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@292248 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/pcre/functions/preg-match-all.xml | 18 ++++++++++++++++-- reference/pcre/functions/preg-match.xml | 10 +++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/reference/pcre/functions/preg-match-all.xml b/reference/pcre/functions/preg-match-all.xml index d9f9cb9e43..cccb97c22d 100644 --- a/reference/pcre/functions/preg-match-all.xml +++ b/reference/pcre/functions/preg-match-all.xml @@ -162,7 +162,7 @@ echo $out[1][0] . ", " . $out[1][1] . "\n"; - Using offset is not equivalent to passing + Using offset is not equivalent to passing substr($subject, $offset) to preg_match_all in place of the subject string, because pattern can contain assertions such as @@ -197,6 +197,16 @@ echo $out[1][0] . ", " . $out[1][1] . "\n"; + + 5.2.2 + + Named subpatterns now accept the + syntax (?<name>) + and (?'name') as well + as (?P<name>). Previous versions + accepted only (?P<name>). + + 4.3.3 @@ -285,7 +295,11 @@ b: 2 c: 3 FOO; -preg_match_all('/(?\w+): (?\d+)/', $str, $matches); +preg_match_all('/(?P\w+): (?P\d+)/', $str, $matches); + +/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however + * the above form is recommended for backwards compatibility */ +// preg_match_all('/(?\w+): (?\d+)/', $str, $matches); print_r($matches); diff --git a/reference/pcre/functions/preg-match.xml b/reference/pcre/functions/preg-match.xml index bdde94fa26..91bd81ac35 100644 --- a/reference/pcre/functions/preg-match.xml +++ b/reference/pcre/functions/preg-match.xml @@ -87,7 +87,7 @@ - Using offset is not equivalent to passing + Using offset is not equivalent to passing substr($subject, $offset) to preg_match in place of the subject string, because pattern can contain assertions such as @@ -286,11 +286,11 @@ domain name is: php.net $str = 'foobar: 2008'; -// Works in PHP 5.2.2 and later. -preg_match('/(?\w+): (?\d+)/', $str, $matches); +preg_match('/(?P\w+): (?P\d+)/', $str, $matches); -// Before PHP 5.2.2, use this: -// preg_match('/(?P\w+): (?P\d+)/', $str, $matches); +/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however + * the above form is recommended for backwards compatibility */ +// preg_match('/(?\w+): (?\d+)/', $str, $matches); print_r($matches);