Home > Article > Backend Development > PHP general knowledge inspection points: regular expressions
1. The role of regular expressions: Split, search, match, replace String
2. Separator: forward slash (/), hash character (#) and Negate the symbol (~).
3. Universal atoms: \d \D \s \S \w \W
##4. Atomic symbols 5. Pattern modifier 6. Back reference7. Greedy mode 8. Regular expression PCRE functionprge_match(), preg_match_all(), preg_replace(), preg()_split().
Solution method Write a requirement Matched string Use regular expression atoms and metacharacters to splice from left to rightFinally add correction pattern Practice common regular expressions ( Mobile phone number, ID card, email, url, etc.) Mobile phone number starting with 139##
$str = '13988888888'; $partten = '/^139/d{8}$/'; preg_match($partten, str, $match); var_dump($match);
$str = '<img id=content"" src="高清无码.jpg" alt="高清无码">'; $partten = '/<img.*?src="(.*?)".*?\/?>/i'; preg_match($partten, $str, $match); var_dump($march);
The above is the detailed content of PHP general knowledge inspection points: regular expressions. For more information, please follow other related articles on the PHP Chinese website!