Home >Backend Development >PHP Tutorial >Regular expressions of PHP basic knowledge inspection points

Regular expressions of PHP basic knowledge inspection points

藏色散人
藏色散人forward
2020-01-27 14:40:283139browse

Regular expressions of PHP basic knowledge inspection points

1. The role of regular expressions: split, search, match, replace strings

2. Separator: forward slash ( /), hash symbol (#) and negation symbol (~).

3. Universal atoms: \d \D \s \S \w \W

Regular expressions of PHP basic knowledge inspection points

4. Atomic symbols

Regular expressions of PHP basic knowledge inspection points

5. Pattern modifier

Regular expressions of PHP basic knowledge inspection points

6. Back reference

7. Greedy mode

8. Regular expression PCRE functionprge_match() , preg_match_all(), preg_replace(), preg()_split().

Solution Question method method

Write a string to be matched

Use atoms and metacharacters of regular expressions to splice from left to right

Finally Add correction mode

Practice common regular expressions (mobile phone number, ID card, email, url, etc.)

Mobile phones starting with 139 Number

$str = '13988888888';
$partten = '/^139/d{8}$/';
preg_match($partten, str, $match);
var_dump($match);

Get the sr value of all img tags in the html page

$str = &#39;<img id=content"" src="高清无码.jpg" alt="高清无码">&#39;;
$partten = &#39;/<img .*?src="(.*?)".*?\/? alt="Regular expressions of PHP basic knowledge inspection points" >/i&#39;;
preg_match($partten, $str, $match);
var_dump($march);

The above is the detailed content of Regular expressions of PHP basic knowledge inspection points. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete