Home > Backend Development > PHP Tutorial > Regular pattern modifier_PHP tutorial

Regular pattern modifier_PHP tutorial

WBOY
Release: 2016-07-13 17:46:22
Original
1092 people have browsed it

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:

修饰符

表达式中的写法

说明

i

(?i)

Ø 忽略大小写

m

(?m)

Ø 增强行锚点模式

s

(?s)

Ø 点号通配模式

x

(?x)

Ø 宽松排列和注释模式

u

 

Ø UTF-8读取正则表达式和目标字符串

X

(?X)

Ø 启用PCRE “额外功能(extra stuff)”

e

 

Ø replacement作为PHP代码(只用于preg_replace

S

 

Ø 启用PCRE的“study”优化尝试

下面三个很少用到

U

(?U)

Ø 交换 "*""*?"的匹配优先含义

A

 

Ø 将整个匹配尝试锚定在起始位置

D

 

Ø "" 只能匹配EOS,而不是EOS之前的换行符

(如果使用了模式修饰符m则不会这样)

Modifier
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('{(.*?)}si',$html,captures))

Excerpted from lostwolf's Blog

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478575.htmlTechArticleAfter the end delimiter, you can follow a variety of pattern modifiers (in PHP terms, called patternmodifier), In some cases, modifiers can also appear inside regular expressions...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template