ID: 38599 Updated by: [EMAIL PROTECTED] Reported By: pilotv at rambler dot ru -Status: Open +Status: Feedback Bug Type: PCRE related Operating System: All PHP Version: 4.4.4 New Comment:
Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.2-win32-latest.zip Previous Comments: ------------------------------------------------------------------------ [2006-08-25 21:02:59] pilotv at rambler dot ru 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 ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38599&edit=1