Regular expression pattern modifier (/ies) _ Regular expression

Source: Internet
Author: User
Tags character classes modifier modifiers
Pattern modifier
Pattern modifier--explain the modifiers used in regular expression patterns
Description
The following is a list of possible modifiers that are currently available in PCRE. The internal PCRE names of these modifiers are in parentheses. The blanks and line breaks in the modifier are ignored, and other characters can cause errors.


I (pcre_caseless)
If you set this modifier, the characters in the pattern will match both the uppercase and lowercase letters.

M (pcre_multiline)
By default, PCRE the target string as a single "line" character (even if it contains newline characters). The "line Start" metacharacters (^) only match the start of the string, and the line end Metacharacters ($) match only the end of the string, or the last character is preceded by a newline character (unless the D modifier is set). This is the same as Perl.

When this modifier is set, line start and end of line match the end of the entire string, and the after and before the line breaks are matched respectively. This is equivalent to the/m modifier of Perl. If there is no "\ n" character in the target string or there is no ^ or $ in the pattern, setting this modifier has no effect.

S (pcre_dotall)
If this modifier is set, the dot meta character (.) in the pattern matches all characters, including line breaks. Without this setting, line breaks are not included. This is equivalent to Perl's/s modifier. Excluding character classes such as [^a] always match newline characters, regardless of whether this modifier is set.

X (pcre_extended)
If this modifier is set, whitespace characters in the pattern are completely ignored in addition to being escaped or outside of the character class, and all characters, including both ends, that are outside of the escaped character class and the next newline character are ignored. This is equivalent to Perl's/x modifier, allowing annotations to be added to complex patterns. Note, however, that this applies only to data characters. Whitespace characters may never appear in a special sequence of characters in a pattern, such as a sequence (?) in which a conditional child pattern is introduced.

E
If this modifier is set, preg_replace () substitutes the reverse reference in the replacement string as a PHP code and replaces the searched string with the result.

Only Preg_replace () uses this modifier, and the other PCRE functions are ignored.

Note: This modifier is not available in PHP3.


A (pcre_anchored)
If this modifier is set, the pattern is coerced to "anchored", which means that only the beginning of the target string is forced to match. This effect can also be implemented through the appropriate pattern itself (the only method implemented in Perl).

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 newline, the dollar sign also matches the character before it (but does not match any other line breaks). This option is ignored if the M modifier is set. There is no equivalent modifier in Perl.

S
When a pattern is used several times, it is worthwhile to analyze it for the sake of accelerated matching. If this modifier is set, an additional analysis is performed. Currently, parsing a pattern is only useful for non-anchored patterns that do not have a single fixed starting character.

U (Pcre_ungreedy)
This modifier reverses the value of the matching number so that it is not the default repetition, and becomes followed by the "?" to become repetitive. This is not compatible with Perl. It can also be set in the pattern (? U) modifier or enable this option after the quantifier followed by a question mark (such as. *?).

X (Pcre_extra)
This modifier enables an additional feature that is incompatible with Perl in a PCRE. Any backslash in the pattern followed by a letter with no special meaning causes an error, thus preserving this combination for future expansion. By default, as with Perl, a backslash is followed by a letter that has no special meaning. No other features are currently controlled by this modifier.

U (PCRE_UTF8)
This modifier enables an additional feature that is incompatible with Perl in a PCRE. The pattern string is treated as UTF-8. This modifier is available under Unix from PHP 4.1.0 and is available under Win32 from PHP 4.2.3. starting from PHP 4.3.5, check the UTF-8 legality of the mode.

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.