note 102217 deleted from regexp.reference.repetition by salathe
| From: | salathe@php.net | Date: | Thu, 03 Feb 2011 09:28:28 +0000 |
| Subject: | note 102217 deleted from regexp.reference.repetition by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176620@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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.