Pattern Modifiers-modifiers for regular Expressions _php tutorial

Source: Internet
Author: User
Pattern Modifiers-modifiers for regular expressions

The following are the decorations available in the current rule expression. The names in parentheses are the internal PCRE names of those modifiers.

I (pcre_caseless)
If this modifier is set, the expression is not case-sensitive.

M (pcre_multiline)
By default, PCRE that the target string value is a single-line string (even if he does contain more than one line). The line start tag (^) matches only the beginning of the string, and the end of line tag ($) matches only the tail of the string, or an end line (unless the E modifier is specified). This is the same as in Perl.

If this modifier is set, the line start and line end structures match the current position of any new line in the target string, or the previous one, and each start and end. This equals the/m modifier inside Perl. This modifier does not work if the target string does not have an "n" character, or if there is no ^ or $ in the pattern.

S (pcre_dotall)
If this modifier is set, a "point" in the pattern will match all characters, including line breaks. Without him, the line will be left out. This modifier is equivalent to the/s modifier inside Perl. An opposite type, such as [^a], will always match the newline character, regardless of the modifier's limit.

X (pcre_extended)
If this modifier is set, the number of spaces in the pattern will be ignored, unless the escape character, or the inner type of a character, and the non-escaped # number outside all character types are ignored. This is equivalent to the/x modifier in Perl, which adds a comment to the complex pattern. Note that this applies only to data characters. The space character will not appear in the specified order of pattern characters.

E
If this modifier is set, Preg_replace () will have a normal replacement in the replacement value, equivalent to the one in the PHP code, and then used to replace the searched string.

Use this modifier only in preg_replace (); Other PCRE functions ignore him.

A (pcre_anchored)
If this modifier is set, the pattern is forced to anchor (anchored), that is, he matches the value to the beginning of the search string. This effect can be achieved through the proper pattern structure itself, which is the only way in Perl.

D (pcre_dollar_endonly)
If this modifier is set, the $ modifier in the pattern will only match the tail in the target string. Without this modifier, the $ character also matches the end of the new line (but no longer precedes the new line). If the M modifier is set, this modifier is ignored. There's nothing like that in Perl.

S
If a pattern is to be used more than once, use a long time to analyze him to improve the speed of the match. If this modifier is used, additional analysis is performed. Currently, the research pattern is only used in non-anchor mode and does not have a fixed start character.

U (Pcre_ungreedy)
This modifier flips the number of "greediness" so that the default is not greedy, but if you follow the question mark (?), you can greedy. This is not compatible with Perl. This can also be passed in the pattern of the (? U) modifier is obtained.

X (Pcre_extra)
This modifier opens the extra functionality, which is incompatible with Perl. Any backslash in the back of any pattern with characters but no special meaning will cause errors, thereby reserving these unions for future expansions. By default, in Perl, there are meaningless characters behind the backslash as normal literal. There are no other control features at this time.



http://www.bkjia.com/PHPjc/532482.html www.bkjia.com true http://www.bkjia.com/PHPjc/532482.html techarticle Pattern Modifiers-modifier for regular expressions The following are the modifiers available in the current rule expression. The names inside the parentheses are the internal PCRE names of those modifiers. I (pcre_caseless) if set ...

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