Before understanding regular expressions, you need to master some basic knowledge of commonly used regular expressions. If you can remember these, it is best to remember them. If you can’t remember, you can look them up when you need to use them. There are just multiple special characters, so regular expressions are Expressions are special. You can view more detailed instructions for details.
For detailed instructions on the preg_match_all function, you can check the PHP manual. This article uses preg_match_all to test the effect of regular expressions.
Example code:
Okay, use the parentheses above to divide the area that needs to be matched. The next step is how to match the content in each expression. We guess that an ID may be letters, numbers or underscores, then this becomes basic. This can be achieved by using square brackets, as follows:
Expression 1: [a-zA-Z0-9_]+ (meaning matching uppercase and lowercase letters, numbers and underscores)
How to match expression 2, because the content of the ID can be Any character, but be careful, it cannot match the < or > characters, because if you match these two characters, all DIVs used later will be matched, so you need to exclude the elements starting with these two characters, that is, they will not match With < or > characters, as follows:
Expression 2: [^<>]+ (indicating that the < and > characters are not matched)
In this way, the subexpression that needs to be matched is realized, but it still needs to be An expression needs to be matched. The method is as follows:
Expression: / '"(Expression 1)"'>(Expression 2)
In this way, a regular expression that matches the ID value and content of each DIV element is implemented, and then the preg_match_all function is used to test as follows: