Home > Article > Backend Development > Regular pattern modifier_PHP tutorial
can be followed by a variety of pattern modifiers after the closing delimiter (called pattern modifier in php terms),
In some cases, modifiers can also appear inside regular expressions to modify certain properties of the pattern. We have seen in some examples the case-insensitive pattern modifier i . The following is a brief introduction to pattern modifiers:
|
Writing in expressions | Description | |||||||||||||||||||||||||||||||||||||||
i | (?i) | Ø Ignore case | |||||||||||||||||||||||||||||||||||||||
m | (?m) | Ø Enhanced row anchor mode | |||||||||||||||||||||||||||||||||||||||
s | (?s) | Ø Dot number wildcard mode | |||||||||||||||||||||||||||||||||||||||
x | (?x) | Ø Loose arrangement and annotation mode | |||||||||||||||||||||||||||||||||||||||
u | Ø Read regular expression and target string in UTF-8 | ||||||||||||||||||||||||||||||||||||||||
X | (?X) | Ø Enable PCRE "Extra stuff (extra stuff)" | |||||||||||||||||||||||||||||||||||||||
e | Ø will replacement as PHP code (only for preg_replace ) | ||||||||||||||||||||||||||||||||||||||||
S | Ø Enable PCRE's "study" optimization attempt | ||||||||||||||||||||||||||||||||||||||||
The following three are rarely used | |||||||||||||||||||||||||||||||||||||||||
U | (?U) | Ø Exchange "*" and "*?" Match priority meaning of | |||||||||||||||||||||||||||||||||||||||
A | Ø Anchor the entire match attempt at the starting position | ||||||||||||||||||||||||||||||||||||||||
D | Ø "$1" can only match EOS, not the one before EOS Line break (not if the pattern modifier m is used) |
Pattern modifiers inside expressions
Within a regular expression, pattern modifiers can appear alone to enable or disable certain features (for example, use "(?i)" to enable case-insensitive matching, Use "(?-i)" to deactivate them. At this time, their scope lasts until the corresponding closing bracket, or until the end of the regular expression if it does not exist. .
They can also be used as pattern modification ranges. For example, "(?i...)" means case-insensitive matching of the content within the brackets " (?-sm:...)" means to disable the s and m modes in this range.
In addition to regular expressions, the pattern modifiers after the end delimiter can be organized in any order. In the following example, 'si' means that case insensitivity and period pass are enabled at the same time. Configuration mode:
If(preg_match('{
Excerpted from lostwolf's Blog