|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-25 21:38 UTC] tony2001@php.net
[2006-08-25 23:17 UTC] pilotv at rambler dot ru
[2006-08-28 06:15 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 16:00:01 2025 UTC |
Description: ------------ (Sorry for my english) Subpattern is not captured for backreference if it is followed by '?' and does not appear in subject string. Reproduce code: --------------- <? $str=<<<EOD <a href="aaa"> <a href='aaa'> <a href=aaa> EOD; // Following RE works properly $re='/<a href=(["\']?)(\w+)\1>/iS'; preg_match_all($re,$str,$regs,PREG_SET_ORDER); print_r($regs); // Following RE works wrong $re='/<a href=(["\'])?(\w+)\1>/iS'; preg_match_all($re,$str,$regs,PREG_SET_ORDER); print_r($regs); ?> Expected result: ---------------- // Produced by 1st RE: Array ( [0] => Array ( [0] => <a href="aaa"> [1] => " [2] => aaa ) [1] => Array ( [0] => <a href='aaa'> [1] => ' [2] => aaa ) [2] => Array ( [0] => <a href=aaa> [1] => [2] => aaa ) ) Actual result: -------------- // Produced by 2nd RE: Array ( [0] => Array ( [0] => <a href="aaa"> [1] => " [2] => aaa ) [1] => Array ( [0] => <a href='aaa'> [1] => ' [2] => aaa ) )