Home  >  Article  >  Backend Development  >  (PHP) Regular expression-the difference between greedy matching and lazy matching

(PHP) Regular expression-the difference between greedy matching and lazy matching

黄舟
黄舟Original
2016-12-30 11:09:191864browse

<?php
/**
 * Created by PhpStorm.
 * User: Ollydebug
 * Date: 2015/11/15
 * Time: 15:20
 */

$pattern = &#39;/google.+123/&#39;;
//$pattern = &#39;/google.+123/&#39;;   修正匹配
//$pattern = &#39;/google.+123/U&#39;;  懒惰匹配
$subject = &#39;I love google__123123123123123123&#39;;

$matches = array();
preg_match($pattern,$subject,$matches);

show($matches);

function show($var){
    if(empty($var)){
        echo &#39;null&#39;;
    }elseif(is_array($var)||is_object($var)){
        // array,object
        echo &#39;<pre class="brush:php;toolbar:false">&#39;;
        print_r($var);
        echo &#39;
'; }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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn