Home > Article > Backend Development > (PHP) Regular expression-the difference between greedy matching and lazy matching
<?php /** * Created by PhpStorm. * User: Ollydebug * Date: 2015/11/15 * Time: 15:20 */ $pattern = '/google.+123/'; //$pattern = '/google.+123/'; 修正匹配 //$pattern = '/google.+123/U'; 懒惰匹配 $subject = 'I love google__123123123123123123'; $matches = array(); preg_match($pattern,$subject,$matches); show($matches); function show($var){ if(empty($var)){ echo 'null'; }elseif(is_array($var)||is_object($var)){ // array,object echo '<pre class="brush:php;toolbar:false">'; print_r($var); echo ''; }else{ //string,int,float echo $var; } } ?>
The above is (PHP) regular expression - the difference between greedy matching and lazy matching. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!