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 ...