PHP-PCRE regular expression metacharacters

Source: Internet
Author: User
PHP extension text processing -- PCRE regular expression syntax 2 -- the power of metacharacters regular expression is that it can have the ability to select and repeat in the mode. Some characters are given special meanings, so that they do not simply represent themselves. in the mode, such encoded characters with special meanings are called metacharacters.

There are two different metacharacters: one can be used anywhere outside the Chinese brackets of the pattern, and the other must be used in square brackets. The metacharacters used outside Square brackets are as follows:

\

It is generally used to escape characters.

^

The start position of the assertion target (or the first row in multi-row mode)

$

The end position of the assertion target (or the end of the row in multi-row mode)

.

Match any character except linefeed (default)

[

Start character class definition

]

End character class definition

|

Start an optional branch

(

Start tag of the sub-group

)

End tag of the sub-group

?

As a quantizer, it indicates 0 or 1 match. It is behind the quantifiers to change the greedy nature of quantifiers.

*

Quantifiers, 0 or multiple matches

+

Quantifiers, matching once or multiple times

{

Start marking of custom quantifiers

}

Custom quantifiers end mark

The section in the square brackets of the pattern is called "character class ". Only the following metacharacters are available in a character class:

\

Escape characters

^

If it is used only as the first character (inside square brackets), it indicates that the character class is reversed.

-

Mark character range

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.