zoukankan      html  css  js  c++  java
  • php正則表達式中的非贪婪模式匹配的使用

    php正則表達式中的非贪婪模式匹配的使用

    通常我们会这么写:

    $str = "http://www.baidu/.com?

    url=www.sina.com/"; preg_match("/http:(.*)com/", $str, $matches); print_r($matches);


    结果:

    Array ( [0] => http://www.baidu/.com?url=www.sina.com [1] => //www.baidu/.com?

    url=www.sina. )


    非贪婪模式匹配:

    $str = "<a http://www.baidu/.com?url=www.sina.com/";
    
    preg_match("/http:(.*?)com/", $str, $matches);
    
    print_r($matches);

    结果:

    Array ( [0] => http://www.baidu/.com [1] => //www.baidu/. )

    简单的说仅仅要在一个字符后面跟上限定个数的特殊字符,匹配就是非贪婪模式了。小伙伴们是否理解了呢? 
  • 相关阅读:
    bzoj1797
    bzoj1266
    bzoj1497
    bzoj1412
    bzoj3156
    JSOI2014第三轮总结
    bzoj1855
    bzoj1044
    codeforces 371D
    codeforces 371B
  • 原文地址:https://www.cnblogs.com/wzjhoutai/p/7253585.html
Copyright © 2011-2022 走看看