Created
October 9, 2012 11:24
-
-
Save alxfv/3858075 to your computer and use it in GitHub Desktop.
Lazy quantifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$subject = <<<EOF | |
<style type="text/css"> | |
p { | |
font-size: 100500px; | |
} | |
</style> | |
some text | |
<style type="text/css"> | |
b { | |
font-weight: normal; | |
} | |
</style> | |
EOF; | |
$pattern = '#<style type="text/css">.*</style>#is'; | |
$s = preg_replace($pattern, '', $subject); | |
echo 'without lazy: ' . $s . '<br />'; | |
/* @see http://www.php.net/manual/en/regexp.reference.repetition.php */ | |
$pattern = '#<style type="text/css">.*?</style>#is'; | |
$s = preg_replace($pattern, '', $subject); | |
echo 'lazy: ' . $s . '<br />'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment