|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-13 13:29 UTC] 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
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
$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 ^^