note 102217 added to regexp.reference.repetition

From: Date: Thu, 03 Feb 2011 04:59:26 +0000
Subject: note 102217 added to regexp.reference.repetition
Groups: php.notes 
Request: Send a blank email to php-notes+get-176612@lists.php.net to get a copy of this message
Using ".*?" makes the repetition Non-greedy, but DONT USE IT UNLESS NEEDED, otherwise preg_match (and the like) may return with error, perhaps silently. For example, the non-greedy element ".*?" is unneccessary: $pattern="/^<.*?>$/m"; $subject="<img src='www.web.com/picture1.jpg' /> <img src='www.web.com/picture2.jpg' />"; preg_match( $pattern, $subject, $match ); and MAY CAUSE FAIL!!! But it fails because you dont need it, and it perhaps confuses PCRE. Instead use Non-Greedy: $pattern="/^<.*>$/m"; and each image tag will be matched separately. ---- Server IP: 69.147.83.197 Probable Submitter: 24.113.79.192 ---- Manual Page -- http://www.php.net/manual/en/regexp.reference.repetition.php Edit -- https://master.php.net/note/edit/102217 Del: integrated -- https://master.php.net/note/delete/102217/integrated Del: useless -- https://master.php.net/note/delete/102217/useless Del: bad code -- https://master.php.net/note/delete/102217/bad+code Del: spam -- https://master.php.net/note/delete/102217/spam Del: non-english -- https://master.php.net/note/delete/102217/non-english Del: in docs -- https://master.php.net/note/delete/102217/in+docs Del: other reasons-- https://master.php.net/note/delete/102217 Reject -- https://master.php.net/note/reject/102217 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176612) next »