#45260 [Opn->Bgs]: Recursive Capturing Subpattern
ID: 45260
Updated by: felipe@php.net
Reported By: ralph at deboom dot biz
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: Debian Etch 4.0+
PHP Version: 5.2.6
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
"If a capturing subpattern is matched repeatedly, it is the last
portion
of the string that it matched that is returned."
- http://pcre.org/pcre.txt
Previous Comments:
------------------------------------------------------------------------
[2008-06-13 13:32:03] ralph at deboom dot biz
$value = 'sub.sub2.sub3.sub4.domain.ext';
if
(preg_match("/^(([a-z0-9]+)(([\.|\-]{1}[a-z0-9]+)|(?R))*\.([a-z]{2,6}))$/i",$value,$match))
{
print_R($match);
}
Thanks to a crappy textarea form I cant properly outline the code..
just indent it yourself ^^
------------------------------------------------------------------------
[2008-06-13 13:29:48] ralph at deboom dot biz
Description:
------------
A recursive subpattern turns out to overwrite data of the previous
matched call... Thus it will only show the last recursive match it made
in the pattern...
Reproduce code:
---------------
$value = 'sub.sub2.sub3.sub4.domain.ext';
if
(preg_match("/^(([a-z0-9]+)(([\.|\-]{1}[a-z0-9]+)|(?R))*\.([a-z]{2,6}))$/i",
$value, $match)) {
print_R($match);
}
Expected result:
----------------
Array
(
[0] => sub.sub2.sub3.sub4.domain.ext
[1] => sub.sub2.sub3.sub4.domain.ext
[2] => sub
[3] => .sub2.sub3.sub4.domain
[4] => .sub2.sub3.sub4.domain
[5] => ext
)
Actual result:
--------------
Array
(
[0] => sub.sub2.sub3.sub4.domain.ext
[1] => sub.sub2.sub3.sub4.domain.ext
[2] => sub
[3] => .domain
[4] => .domain
[5] => ext
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45260&edit=1
Thread (5 messages)