Skip to content

Instantly share code, notes, and snippets.

@alxfv
Created October 9, 2012 11:24
Show Gist options
  • Save alxfv/3858075 to your computer and use it in GitHub Desktop.
Save alxfv/3858075 to your computer and use it in GitHub Desktop.
Lazy quantifier
<?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