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

Regular expressions of PHP basic knowledge inspection points

藏色散人
Release: 2023-04-08 10:44:02
forward
3142 people have browsed it

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

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template