Php regular expression modifier

Source: Internet
Author: User
What are php regular expression I, is, s, isU, and so on? 1. Regular expression operation sequence () parentheses are the highest as they are processed in memory *? + {} Duplicate matching content second ^ $ B boundary processing third condition processing fourth final calculation matching in order 2. Regular expression pattern modifier I regular content is case insensitive during matching (default yes) m matches the first content or the last php regular expression pattern modifier

What are PHP regular expressions/I,/is,/s,/isU and so on?


1. Regular expression operation sequence

() Parentheses are the highest for memory processing.

*? + {} Duplicate matching content followed

^ $ \ B boundary processing third

Condition processing fourth

Finally, matching is calculated in the order of operation.

2. Regular expression pattern modifier

I. The regular content is case-insensitive during matching (the default value is case-sensitive)

M uses multiple lines to identify and match the first or last content

S cancels the escape carriage return to match a single row, such as. match.

X ignore the blank in the regular expression

A force match from scratch

D Force $ No content at the end of the match \ n

U prohibit greedy match. only the last match is tracked and ended,

Regular expressions commonly used in collection programs

I matching case


In s mode, the DOT metacharacter (.) matches all characters, including line breaks.


In x mode, white space characters are ignored except escaped characters or in character classes. in addition to the unescaped character classes # and all characters between the next line break, including two ends, are ignored.


If this modifier is set for A (PCRE_ANCHORED), the mode is forced to "anchored", that is, to force matching only from the beginning of the target string, that is, it is automatically added to the beginning of the mode ^.


D (PCRE_DOLLAR_ENDONLY) if this modifier is set, the dollar character in the pattern matches only the end of the target string. Without this option, if the last character is a line break, the dollar sign will also match before this character (but not before any other line breaks ). If the m modifier is set, ignore this option. Perl does not have an equivalent modifier. 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) this modifier reverses the value of the matching quantity so that it is not the default repetition, but is followed by "?" . This is incompatible with Perl. You can also set in the mode (? U) to enable this option.


X (PCRE_EXTRA) this modifier enables additional features that are not compatible with Perl in a PCRE. Any backslash followed by a letter with no special meaning in the mode leads to an error, so that this combination is retained for future expansion. By default, like Perl, a backslash followed by a letter without special meaning is treated as the letter itself. No other features are currently controlled by this modifier. That is: greedy mode. the maximum match is:/a [\ w] +? E/U matches abceade in abceadeddd instead of abce. if U correction is not added, it matches abce u (PCRE_UTF8). This modifier enables an additional feature that is incompatible with Perl in a PCRE. The pattern string is treated as a UTF-8. This modifier is available in Unix from PHP 4.1.0 and win32 from PHP 4.2.3.

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.