PHP regular expression suffix_PHP tutorial

WBOY
Release: 2016-07-13 17:51:50
Original
1521 people have browsed it

Perl-style regular expressions allow single-character options (flags) to be placed after the regular expression pattern to modify the interpretation or behavior of the match. For example, to do a case-insensitive match, you can simply use the i flag:
preg_match('/cat/i', 'Stop, Catherine!'); // returns true returns true
Table 4-12 shows the modifiers from Perl supported in Perl-compatible regular expressions:
Table 4-12: Perl flags

修饰符 意 义
/regexp/i 不区分大小写的匹配
/regexp/s 使句点(.)匹配任何字符,包括换行符(n)
/regexp/x 从模式中删除空白符和注释
/regexp/m 使^匹配换行符 (n)之后的内容,美元符号($)匹配换行符 (n)之前的内容
/regexp/e 如果替换字符串是PHP代码,使用eval()执行该代码来得到实际的替换字符串。
PHP's Perl-compatible regular expression functions also support other modifiers not supported in Perl, as shown in Table 4-13:
Table 4-13: Other PHP flags
修饰符 意 义
/regexp/U 颠倒子模式的贪婪性;*和+尽可能少地匹配而不是尽可能多。
/regexp/u 把模式字符串当作UTF-8编码对待
/regexp/X 如果一个反斜杠之后跟着没有特殊意义的字符,将产生一个错误
/regexp/A 把锚定位在字符串的开头就像模式中有^一样
/regexp/D 使$字符仅匹配一行的末尾
/regexp/S 使表达式解析器更加小心地检查模式的结构,使得第二次运行时(如在一个循环中)加快速度

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478166.htmlTechArticlePerl-style regular expressions allow single character options (flags) to be placed after the regular expression pattern to modify the match interpretation or behavior. For example, to do a case-insensitive match,...
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