Here, we will briefly introduce the usage of non-Greedy pattern matching in php regular expressions through examples. If you need it, please refer to it.
Here, we will briefly introduce the usage of non-Greedy pattern matching in php regular expressions through examples. If you need it, please refer to it.
We usually write as follows:
The Code is as follows:
$ Str = "";
Preg_match ("/http :(. *) com/", $ str, $ matches );
Print_r ($ matches );
Result:
The Code is as follows:
Array ([0] => [1] => // www. baidu/. com? Url = www. sina .)
Non-Greedy pattern matching:
The Code is as follows:
$ Str = "";
Preg_match ("/http :(.*?) Com/", $ str, $ matches );
Print_r ($ matches );
Result:
The Code is as follows:
Array ([0] => [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?
,