Use the preg regular function in php. In php, the preg regular function uses 1. The difference between preg_match and preg_match_all is that preg_match matches only once. And preg_match_all match until the string is used by the preg regular function in php.
1. differences between preg_match and preg_match_all
The difference between preg_match and preg_match_all is that preg_match matches only once. Preg_match_all matches all until the string ends. Example:
String 'ABCDE' (length = 5) array (size = 1) 0 => array (size = 3) 0 => string 'ABCDE' (length = 5) 1 => string 'ABCDE' (length = 5) 2 => string 'ABCDE' (length = 5) */?>
2. differences between greedy mode and non-greedy mode
For example, String str = "abcaxc ";
Patter p = "AB * c ";
Greedy match: Regular expressions tend to match the maximum length, that is, greedy match. For example, if the preceding pattern p is used to match the str string, the result is: abcaxc (AB * c ).
Non-greedy match: it is good to match the result with fewer matching characters. For example, if the preceding pattern p is used to match the string str, the result is: abc (AB * c ).
Example:
String 'http: // www. baidu/. com? Url = www.sina.com '(length = 38) 1 => string' // www. baidu/. com? Url = www. sina. '(length = 30) array (size = 2) 0 => string 'http: // www. baidu /. com '(length = 21) 1 => string' // www. baidu /. '(length = 13) */?>
3. differences between preg_match_all parameters PREG_PATTERN_ORDER (default) and PREG_SET_ORDER
]+>(.*)
]+>|U", "start: this is a testend", $out1);var_dump($out1);echo('PREG_SET_ORDER');preg_match_all("|<[^>]+>(.*)
]+>|U", "start: this is a testend", $out2, PREG_SET_ORDER);var_dump($out2);/*PREG_PATTERN_ORDERarray (size=2) 0 => array (size=3) 0 => string 'start: ' (length=14) 1 => string 'this is a test' (length=21) 2 => string 'end' (length=10) 1 => array (size=3) 0 => string 'start: ' (length=7) 1 => string 'this is a test' (length=14) 2 => string 'end' (length=3)PREG_SET_ORDERarray (size=3) 0 => array (size=2) 0 => string 'start: ' (length=14) 1 => string 'start: ' (length=7) 1 => array (size=2) 0 => string 'this is a test' (length=21) 1 => string 'this is a test' (length=14) 2 => array (size=2) 0 => string 'end' (length=10) 1 => string 'end' (length=3) */?>
For more information, see preg_match_all.
Comparison 1. differences between preg_match and preg_match_all: preg_match matches only once. And preg_match_all match until the string ends...