PHP regex/I,/s,/x,/u,/u,/A,/D,/s, etc. pattern modifiers

Source: Internet
Author: User

I (pcre_caseless)

If this modifier is set , the letters in the pattern are case insensitive and match .

m (pcre_multiline)

By default, pcre that the target string is made up of one-line characters(However, it may actually contain multiple lines), "beginning "meta character (^) matches only the starting position of the string ,  and " end "meta-character ($) matches only the end of the string ,  or the last newline character is set d Modifier perl the same .  when this modifier is set " and "end " will match any newline character in the target string before or after the Span lang= "en-US" >,  in addition ,  also match the first and last position of the target string .  this equates to perl /m modifier .  if the target string   does not have ,  or mode does not appear ^ or $,  settings this modifier has no effect

s (pcre_dotall)

If this modifier is set , the dot character in the pattern matches all characters , including line breaks . If you do not have this modifier , the dot number does not match the line break . This modifier is equivalent to the/ s modifier in Perl . An inverse character class such as [^a] always matches a newline character , and does not depend on the modifier's settings .

x (pcre_extended)

If this modifier is set , the non-escaped or blank data characters in the pattern are always ignored and are located outside of an escaped character class #字符和下一个换行符之间的字符也被忽略. This modifier is equivalent to The /x modifier in Perl , which allows comments to be included in the compiled mode . Note : This is used only for data characters . Whitespace characters cannot appear in a special sequence of characters in a pattern , such as a sequence (? A conditional subgroup was introduced ( This syntax defines a special character sequence in which a white-space character causes a compilation error .) such as (? ( will cause errors .).

e (preg_replace_eval)

If this modifier is set , Preg_replace () is replaced with a back reference to the replacement string , evaluates the replacement string as a PHP code (eval function ), and uses the execution result As a string that actually participates in the substitution . Single quotes , double quotes , backslashes (\), and null characters are escaped with a backslash when the back reference is replaced .

Tip

Make sure that the replacement parameter is made up of a valid PHP code string , otherwise PHP will generate an explanatory error on the line called Preg_replace () .

Note : Only preg_replace () uses this modifier , and the other pcre function ignores this modifier .

A (pcre_anchored)

If this modifier is set , the pattern is coerced to "anchored " mode, which means that the constraint matches the search only from the beginning of the target string . This effect can also be constructed using the appropriate pattern , and this is the only way for Perl to implement this pattern .

D (pcre_dollar_endonly)

If this modifier is set , the meta-character dollar sign in the pattern matches only the end of the target string . If this modifier is not set , the dollar sign also matches the newline character if the string ends with a newline character (but does not match any previous line break ). If the modifier mis set, this modifier is ignored . There is no modifier equivalent to this modifier in Perl .

S

When a pattern needs to be used more than once, it is worth taking some time to perform some additional analysis in order to get a match speed boost. If this modifier is set , this additional analysis will be performed . Currently , This analysis of a pattern only applies to non-anchored pattern matching (that is, there is no separate fixed-start character ).

U (pcre_ungreedy)

This modifier reverses the "greedy " pattern of quantifiers . Make quantifiers default to non-greedy , followed by quantifiers ? Way to make it greedy . This is incompatible with Perl . It can also be set using the pattern modifier (? U) , or mark its non-greed with a question mark after the quantifier (e.g. . *? ).

Note :

In non-greedy mode , characters that exceed pcre.backtrack_limit are usually not matched.

X (Pcre_extra)

This modifier opens the pcre and perl incompatible attachments feature . After any backslash in the pattern, ingen a character with no special meaning causes an error that preserves these characters for backward compatibility . By default , in Perl , a backslash followed by a character with no special meaning is considered to be the original of the character . No other feature is currently controlled by this modifier .

J (pcre_info_jchanged)

Internal option settings (? J) Modify the local pcre_dupnames option. Allows the name of the child group . ( Note: The external/j setting generates an error only through the internal option setting .)

u (PCRE8)

This modifier opens an additional feature that is incompatible with Perl . The pattern string is considered utf-8 . This modifier is from the Unix version of php 4.1.0 or higher , and the Win32 version of PHP 4.2.3 begins to be available . PHP 4.3.5 starts checking the utf-8 legitimacy of the pattern. This modifier turns on additional functionality of PCRE, that's incompatible with Perl. Pattern strings is treated as UTF-8. This modifier was available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on Win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

Transferred from: http://blog.csdn.net/cjsyr_cjsyr/article/details/53688984

PHP regex/I,/s,/x,/u,/u,/A,/D,/s, etc. pattern modifiers

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.