Php regular expression modifier usage example

Source: Internet
Author: User
Tags php regular expression
This article mainly introduces the usage of php regular correction operators, and analyzes the functions, usage, and precautions of php regular correction operators in combination with examples, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:

 

Modifier:

POSIX compatible regular expressions do not have modifiers.

Possible modifiers in PERL-compatible regular expressions (space and line feed in the modifier are ignored, and other characters may cause errors ):

I (PCRE_CASELESS ):
Case insensitive for matching.

M (PCRE_MULTILINE ):
When this modifier is set, in addition to matching the beginning and end of the entire string, the row start (^) and the row end ($) also match the line break (\ n) respectively) and before.

S (PCRE_DOTALL ):
If this modifier is set, the DOT metacharacters (.) in the pattern match all characters, including line breaks. If this parameter is not set, line breaks are not included.

X (PCRE_EXTENDED ):
If this modifier is set, the white space characters in the mode are ignored in addition to escape characters or in the character class.

E:
If this modifier is set, preg_replace () replaces the reverse reference in the replacement string as a normal replacement, evaluate it as the PHP code, and use the result to replace the searched string. This modifier is only used by preg_replace (), which is ignored by other PCRE functions.

A (PCRE_ANCHORED ):
If this modifier is set, the pattern is forced to "anchored", that is, it is forced to match only from the beginning of the target string.

D (PCRE_DOLLAR_ENDONLY ):
If this modifier is set, the row end ($) in the pattern matches only the end of the target string. Without this option, if the last character is a line break, it will also be matched. If the m modifier is set, ignore this option.

S:
When a mode is used several times, it is worth analyzing for acceleration matching. If this modifier is set, additional analysis is performed. Currently, the analysis mode is only useful for non-anchored modes without a single fixed start character.

U (PCRE_UNGREEDY ):
Make "?" Is greedy by default.

X (PCRE_EXTRA ):
Any backslash followed by a letter with no special meaning in the pattern causes an error, so that this combination is retained for future expansion. By default, a backslash followed by a letter without special meaning is treated as the letter itself.

U (PCRE_UTF8 ):
The modulo string is treated as a UTF-8.

Note:

Pattern Modifiers)

I-matching uppercase and lowercase letters at the same time
M-treat strings as multiple rows
S-treats a string as a single line, and line breaks are treated as common characters so that "." matches any character.
The white space in X-mode is ignored.
U-match to the nearest string
E-use the replaced string as the expression

I hope this article will help you with PHP programming.

For more details about php regular expression modifier usage examples, refer to PHP Chinese network!

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.