Skip to Content
PHP编程:第4版
book

PHP编程:第4版

by Kevin Tatroe, Peter MacIntyre
January 2021
Intermediate to advanced
505 pages
9h 45m
Chinese
Publishing House of Electronics Industry
Content preview from PHP编程:第4版
正则表达式
115
左括号,以此类推。例如下面的例子,它标识了重复的单词
preg_match("/([[:alpha:]]+)\s+\1/", "Paris in the the spring", $m);
//
返回
true
$m[1]
"the"
preg_match()
最多可以捕获
99
个子模式,大于第
99
个的子模式将被忽略。
后缀选项
Perl
风格的正则表达式允许把一个单字符(标志)放在正则表达式的后面,从而改变表
达式的解析、行为或者匹配方式。例如,要匹配大小写敏感,只需要在后面加一个
i
标志:
preg_match("/cat/i", "Stop, Catherine!"); //
返回
true
4-10
展示了
Perl
兼容的正则表达式支持的
Perl
里面的修饰符。
4-10Perl标志
修饰符 含义
/
regexp
/i
匹配大小写
/
regexp
/s
使句点匹配任何字符,包括换行符
\n
/
regexp
/x
去掉空白和注释
/
regexp
/m
使得
^
匹配换行符
\n
之后的内容,
$
匹配换行符
\n
之前的内容
/
regexp
/e
如果替换字符串是
PHP
代码,使用
eval()
执行该代码,可得到实际替
换的字符串
PHP
中的
Perl
兼容的正则表达式函数也支持在
Perl
中不支持的其他修饰符,如表
4-11
所示。
4-11:其他PHP修饰符
修饰符 含义
/
regexp
/U
颠倒子模式的贪婪性。
*
+
尽可能少地匹配而不是尽可能多
/
regexp
/u
把模式字符串当作
UTF-8
编码
/
regexp
/X
如果一个反斜杠之后跟着没有特殊意义的字符,则产生一个错误 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez

Publisher Resources

ISBN: 9787121404634