Regular expression modifier

Source: Internet
Author: User
After the end separator, you can follow multiple pattern modifiers (called patternmodifier in php). In some cases, modifiers can also appear in regular expressions, modifies certain properties of a pattern. We have seen in some examples the case-insensitive mode... SyntaxHighlighter. all ();

 

After the separator ends, you can follow multiple pattern modifiers (called pattern modifier in php ),

In some cases, modifiers can also appear inside regular expressions to modify certain properties of the pattern. We have seen in some examples that I is a case-insensitive pattern modifier. The pattern modifier is described below:

 

 

Modifier

Writing in expressions

Description

I

(? I)

Ignore case sensitivity

M

(? M)

Enhanced line anchor mode

S

(? S)

Ø point/number wildcard mode

X

(? X)

Ø loose arrangement and comment mode

U

 

Reading regular expressions and target strings with UTF-8

X

(? X)

Enable "extra stuff" for PCRE )"

E

 

Ø use replacement as PHP code (for preg_replace only)

S

 

Enable "study" Optimization of PCRE

The following three are rarely used.

U

(? U)

Exchange "*" and "*? Matching priority

A

 

Ø pin the entire matching attempt at the starting position

D

 

Ø "$1" can only match with EOS, not the line break before EOS

(This is not the case if the pattern modifier m is used)

 

Pattern modifier inside the expression

In a regular expression, a pattern modifier can appear independently to enable or disable certain features (for example "(? I) "to enable case-insensitive matching, use "(? -I. At this time, their scope of action continues to the end brackets. if they do not exist, they continue to the end of the regular expression.

 

They can also be used as pattern modifier ranges such "(? I...) "indicates that the content in the brackets is case-insensitive "(? -Sm:...) "indicates that s and m modes are disabled in this range.

 

In addition to regular expressions, the pattern modifiers after the ending separator can be organized in any order. in the following example, 'Si' indicates that the case-insensitive and point-number wildcard modes are enabled simultaneously:

If (preg_match ('{(.*?)} Si', $ html, captures ))

 

From lostwolf's Blog

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.