#45260 [Opn]: Recursive Capturing Subpattern

From: Date: Fri, 13 Jun 2008 13:32:03 +0000
Subject: #45260 [Opn]: Recursive Capturing Subpattern
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125745@lists.php.net to get a copy of this message
ID: 45260 User updated by: ralph at deboom dot biz Reported By: ralph at deboom dot biz Status: Open Bug Type: PCRE related Operating System: Debian Etch 4.0+ PHP Version: 5.2.6 New Comment: $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 ^^ Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#125745) next »