PHP—PCRE regular expression metacharacters

伊谢尔伦
Release: 2016-11-21 17:27:47
Original
1320 people have browsed it

The power of regular expressions comes from their ability to select and repeat patterns. Some characters are given special meanings so that they no longer simply represent themselves. These encoded characters with special meanings in the pattern are called metacharacters.

There are two different metacharacters: one can be used anywhere outside the square brackets in the pattern, and the other needs to be used within the square brackets. The metacharacters used outside square brackets are as follows:

Generally used to escape characters

^

Assert the beginning of the target (or the beginning of the line in multiline mode)

$

Assert the end of the target position (or end of line in multiline mode)

.

matches any character except newline (default)

[

start character class definition

]

end character class definition

|

Start an optional branch

(

Start tag of subgroup

)

End tag of subgroup

?

As a quantifier, indicating 0 or 1 matches. Placed after the quantifier to change the greedy nature of the quantifier.

*

Quantifier, 0 or more matches

+

Quantifier, 1 or more matches

{

Custom quantifier start tag

}

Custom quantifier end tag

Pattern Chinese The part inside the brackets is called the "character class". The only metacharacters available within a character class are the following:

escape character

^

only when used as the first character (inside square brackets), indicates the negation of the character class

-

marker character Range



Related labels:
php
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!