Regular Expression Pattern modifier, regular expression Modifier
I (PCRE_CASELESS)
If this modifier is set, the letters in the mode are case-insensitive.
M (PCRE_MULTILINE)
By default, PCRE considers the target string to be composed of single-line characters (however, it may actually contain multiple lines), and the "first line" metacharacter (^) only match the start position of the string, while the metacharacter ($) at the end of the line matches only the end of the string or the last line break (unless the D modifier is set ). This behavior is the same as perl. After this modifier is set, "first line" and "last line" match any line break in the target string before or after. In addition, it also matches the start and end positions of the target string respectively. This is equivalent to the/m modifier of perl. If the target string does not contain the "\ n" character, or the "^" or "$" character does not appear in the mode, setting this modifier will not affect you.
S (PCRE_DOTALL)
If this modifier is set, the dot metacharacters in the mode match all characters, including line breaks. If this modifier does not exist, the dot does not match the linefeed. This modifier is equivalent to the/s modifier in perl. An anti-character class such as [^ a] Always matches a line break, and does not rely on the modifier settings.
X (PCRE_EXTENDED)
If this modifier is set, blank data characters in the mode that are not escaped or not in the character class are always ignored, in addition, the characters between the # character and the next line break located outside of an unescaped character class are also ignored. This modifier is equivalent to the/x modifier in perl, so that the compiled mode can contain comments. Note: This is only used for data characters. Blank characters cannot appear in a special character sequence in the mode, such as a sequence (? (A condition sub-group is introduced. If there is a blank character in the Special Character Sequence defined by the syntax, compilation errors may occur. For example (? (It will cause an error ).
E (PREG_REPLACE_EVAL)
Warning
This feature has been deprecated since PHP 5.5.0. We strongly recommend that you do not use this feature.
If this deprecated modifier is set, preg_replace () is replaced with the replacement string after being referenced, the replaced string is evaluated and executed as the php code (eval function mode), and the execution result is used as the string to be replaced. Single quotation marks, double quotation marks, backslash (\), and NULL characters are escaped by backslash when being replaced by backward references.
Caution
The addslashes () function is run on each matched backreference before the substitution takes place. as such, when the backreference is used as a quoted string, escaped characters will be converted to literals. however, characters which are escaped, which wocould normally not be converted, will retain their slashes. this makes use of this modifier very complicated.
Caution
Make sure that the replacement parameter is composed of valid php code strings. Otherwise, php will generate an interpretation error on the row called by preg_replace.
Caution
Use of this modifier is discouraged, as it can easily introduce security vulnerabilites:
<?php$html = $_POST['html'];// uppercase headings$html = preg_replace('(
The above example code can be easily exploited by passing in a string such as
To prevent this kind of remote code execution vulnerability the preg_replace_callback () function shocould be used instead:
<?php$html = $_POST['html'];// uppercase headings$html = preg_replace_callback('(
Note:
Only preg_replace () uses this modifier, which is ignored by other PCRE functions.
A (PCRE_ANCHORED)
If this modifier is set, the pattern is forced to be "anchored", that is, the constraint match enables it to search only from the starting position of the target string. This effect can also be constructed using the appropriate mode, and this is also the only way for perl to implement this mode.
D (PCRE_DOLLAR_ENDONLY)
If this modifier is set, the dollar sign in the schema matches only the end of the target string. If this modifier is not set, when the string ends with a linefeed, the dollar symbol will match the linefeed (but will not match any previous linefeeds ). If the modifier m is set, this modifier is ignored. There is no modifier equivalent to this modifier in perl.
S
When a mode needs to be used multiple times, it is worthwhile to spend some time to analyze it to improve the matching speed. If this modifier is set, this additional analysis will be executed. Currently, this analysis of a pattern is only applicable to non-anchoring pattern matching (that is, there is no separate fixed start character ).
U (PCRE_UNGREEDY)
This modifier reverses the "greedy" pattern of quantifiers. The quantifiers are non-Greedy by default, followed by quantifiers? To make it greedy. This is incompatible with perl. It can also be set using the in-mode modifier (? U), or mark it with a question mark (such as. *?) after the quantifiers .*?).
Note:
In non-Greedy mode, it is generally not allowed to match characters that exceed pcre. backtrack_limit.
X (PCRE_EXTRA)
This modifier enables the attachment feature that is not compatible with perl. After any backslash in the mode, a character with no special meaning will cause an error, so as to retain these characters to ensure backward compatibility. By default, in perl, The backslash is followed by a character without special meaning and is considered as the original character of the character. Currently, no other features are controlled by this modifier.
J (PCRE_INFO_JCHANGED)
Set internal options (? J) modify the local PCRE_DUPNAMES option. Allow sub-groups to have multiple names .)
U (PCRE_UTF8)
This modifier opens an additional feature that is incompatible with perl. The pattern string is considered to be UTF-8. This modifier is available for php 4.1.0 or later in unix and php 4.2.3 in win32. Php 4.3.5 starts to check the validity of the UTF-8 mode.