Let's talk about the use of non-greedy pattern matching in php regular expressions, and talk about regular expressions. Let's talk about the use of non-greedy pattern matching in php regular expressions. we usually write the regular expression like this: Copy the code as follows: $ strwww. baidu. comurlwww. about the use of non-greedy pattern matching in php regular expressions, and about regular expressions
We usually write as follows:
The code is as follows:
$ Str = "http://www.baidu/.com? Url = www.sina.com /";
Preg_match ("/http :(. *) com/", $ str, $ matches );
Print_r ($ matches );
Result:
The code is as follows:
Array ([0] => http://www.baidu/.com? Url = www.sina.com [1] => // www. baidu/. com? Url = www. sina .)
Non-greedy pattern matching:
The code is as follows:
$ Str = "http://www.baidu/.com? Url = www.sina.com /";
Preg_match ("/http :(.*?) Com/", $ str, $ matches );
Print_r ($ matches );
Result:
The code is as follows:
Array ([0] => http://www.baidu/.com [1] => // www. baidu /.)
Simply put, as long as a character is followed by a specified number of special characters, matching is a non-greedy mode. Have you understood this?
The code is as follows: $ str = "http://www.baidu/.comurl=www.sin...