PHP regular mode modifier specific application method Analysis _php Tutorial

Source: Internet
Author: User
Tags character classes modifiers
For beginners mode modifier:

The pattern modifier is marked outside the entire pattern.

I: The characters in the pattern will match the uppercase and lowercase letters.

M: string is treated as multiple lines.

S: Treats the string as a single line and as a newline character.

x: Ignores whitespace in the pattern.

A: Forces the match to start only from the beginning of the target string.

D: The dollar character in the pattern matches only the end of the target string.

U: Matches the nearest string.

The following is a list of PHP regular mode modifiers that are currently available in PCRE. The internal PCRE names of these modifiers are in parentheses. Spaces and line breaks in the modifier are ignored, and other characters cause errors.

I (pcre_caseless)

If this modifier is set, the characters in the pattern will match the uppercase and lowercase letters.

M (pcre_multiline)

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

When this modifier is set, line start and line end match the beginning and end of the entire string, respectively, after and before the newline character. This is equivalent to Perl's/M modifier. 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 the PHP regular mode modifier is set, the dot character (.) in the pattern matches all characters, including the line break. Without this setting, the line break is not included. This is equivalent to Perl's/s modifier. Exclude character classes such as [^a] always match line breaks, regardless of whether this modifier is set.

X (pcre_extended)

If this modifier is set, the whitespace characters in the pattern are ignored, in addition to being escaped or completely ignored outside of the character class, and all characters, including both ends, of the # and the next newline character outside the non-escaped characters class. This is equivalent to Perl's/x modifier, which allows annotations to be added to complex schemas. 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 that introduces conditional sub-patterns (? (middle).

E If this modifier is set, Preg_replace () makes a normal substitution of the inverse reference in the replacement string, evaluates it as a PHP code, and replaces the searched string with its result.

Only Preg_replace () uses this modifier, and the other PCRE function ignores it.

Note: This PHP regular mode modifier is not available in PHP3.

A (pcre_anchored)

If this modifier is set, the pattern is coerced to "anchored", which forces the match to start only from the beginning of the target string. This effect can also be implemented by the appropriate pattern itself (the only method implemented in Perl).

D (pcre_dollar_endonly)

If this PHP regular mode 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 this character before (but not before any other line break). This option is ignored if the M modifier is set. There is no equivalent modifier in Perl.

S when a pattern is to be used several times, it is worth analyzing it to speed up the match. If this modifier is set, 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 PHP regular mode modifier Reverses the value of the matched number so that it is not the default repetition, but instead becomes the "?" in the back. only to become repetitive. This is not compatible with Perl. You can also set the (? U) modifier or enable this option after the quantifier with a question mark (such as. *?).

X (Pcre_extra)

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

U (PCRE_UTF8)

This modifier enables additional features in a PCRE that are incompatible with Perl. 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 legitimacy of the mode.


http://www.bkjia.com/PHPjc/446315.html www.bkjia.com true http://www.bkjia.com/PHPjc/446315.html techarticle for beginner mode modifiers: The pattern modifier is marked outside the entire pattern. I: The characters in the pattern match the uppercase and lowercase letters. M: the string is treated as multiple lines. S: Treats the string as a single ...

  • 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.