(PHP)正则表达式-贪婪匹配与懒惰匹配的区别
程序员文章站
2022-04-20 17:57:03
...
<?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>'; print_r($var); echo '</pre>'; }else{ //string,int,float echo $var; } } ?>
以上就是(PHP)正则表达式-贪婪匹配与懒惰匹配的区别的内容,更多相关内容请关注PHP中文网(www.php.cn)!
上一篇: 学习编程那点事