On the use of non-greedy pattern matching in regular expression of PHP, a brief talk on regular expression _php tutorial

Source: Internet
Author: User

On the use of non-greedy pattern matching in regular expressions of PHP, talking about regular expressions


Usually we write this:

Copy the Code code as follows:
$str = "http://www.baidu/.com?url=www.sina.com/";
Preg_match ("/http: (. *) com/", $str, $matches);
Print_r ($matches);

Results:

Copy the Code code as follows:
Array ([0] = http://www.baidu/.com?url=www.sina.com [1] =//www.baidu/.com?url=www.sina.)

Non-greedy pattern matching:

Copy the Code code as follows:
$str = "http://www.baidu/.com?url=www.sina.com/";
Preg_match ("/http: (. *?) com/", $str, $matches);
Print_r ($matches);

Results:

Copy the Code code as follows:
Array ([0] = http://www.baidu/.com [1] =//www.baidu/.)

Simply put, the match is a non-greedy mode as long as you follow a character with a limited number of characters. Do the little friends understand?

http://www.bkjia.com/PHPjc/917037.html www.bkjia.com true http://www.bkjia.com/PHPjc/917037.html techarticle on the use of non-greedy pattern matching in regular expressions of PHP, talking about regular expressions we usually write this: Copy the code as follows: $str = "Http://www.baidu/.comurl=www.sin ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.