Home  >  Article  >  Backend Development  >  PHP general knowledge inspection points: regular expressions

PHP general knowledge inspection points: regular expressions

little bottle
little bottleforward
2019-04-16 13:37:112118browse

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 reference

7. Greedy mode

8. Regular expression PCRE function

prge_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 right

Finally 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);

Remove all img tags in the html page The value of sr

$str = '<img id=content"" src="高清无码.jpg" alt="高清无码">';
$partten = '/<img.*?src="(.*?)".*?\/?>/i';
preg_match($partten, $str, $match);
var_dump($march);

[Recommended course: PHP video tutorial

]

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!

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