当前位置:Gxlcms > PHP教程 > (PHP)正则表达式-贪婪匹配与懒惰匹配的区别

(PHP)正则表达式-贪婪匹配与懒惰匹配的区别

时间:2021-07-01 10:21:17 帮助过:11人阅读

<?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.gxlcms.com)!

人气教程排行