php正则表达式后缀
Jun 13, 2016 am 10:50 AM
perlphpsuffixcharacterBundlelogomodelregularofexpressionOptionsstyle
Perl风格的正则表达式允许把单个字符选项(标志)放在正则表达式模式后面来修改匹配的解释或行为。例如,要进行不区分大小写的匹配,可以简单地使用i标志:
preg_match('/cat/i', 'Stop, Catherine!'); // returns true返回true
表4-12显示了在Perl兼容正则表达式中支持的来自Perl的修饰符:
表4-12:Perl标志
修饰符 | 意 义 |
/regexp/i | 不区分大小写的匹配 |
/regexp/s | 使句点(.)匹配任何字符,包括换行符(\n) |
/regexp/x | 从模式中删除空白符和注释 |
/regexp/m | 使^匹配换行符 (\n)之后的内容,美元符号($)匹配换行符 (\n)之前的内容 |
/regexp/e | 如果替换字符串是PHP代码,使用eval()执行该代码来得到实际的替换字符串。 |
PHP的Perl兼容正则表达式函数也支持在Perl中不支持的其他修饰符,如表4-13所示:
表4-13:其他的PHP标志
修饰符 | 意 义 |
/regexp/U | 颠倒子模式的贪婪性;*和+尽可能少地匹配而不是尽可能多。 |
/regexp/u | 把模式字符串当作UTF-8编码对待 |
/regexp/X | 如果一个反斜杠之后跟着没有特殊意义的字符,将产生一个错误 |
/regexp/A | 把锚定位在字符串的开头就像模式中有^一样 |
/regexp/D | 使$字符仅匹配一行的末尾 |
/regexp/S | 使表达式解析器更加小心地检查模式的结构,使得第二次运行时(如在一个循环中)加快速度 |
Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.