PHP general knowledge inspection points: regular expressions

little bottle
Release: 2023-04-05 21:04:01
forward
2118 people have browsed it

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);
Copy after login

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);
Copy after login

[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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!