Changing Regex Greediness in PHP
The modifier U makes it so that all
repetition operators become non-greedy by default,
and adding ?, on the contrary,
will add greediness to them:
<?php
preg_replace('#x.+x#U', '!', 'xax xaax xaaax'); // returns '! ! !'
?>