Skip to Content
Perl语言入门(第8版)
book

Perl语言入门(第8版)

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2022
Beginner to intermediate
390 pages
7h 5m
Chinese
Southeast University Press
Content preview from Perl语言入门(第8版)
140
7
现在我们需要转义的元字符又多了这些:
?
*
+
{
。在
Perl 5.26
之前,左花括号
{
)有时不用转义也可以表示该字符本身,但随着
Perl
的沿革,正则表达式的特性
也在扩展,
{
被赋予了更多能力和使命,所以在之后的版本中都需要转义,才能表示
它本身。相比之下,右花括号因为不会开启任何特殊处理,也就不需要转义了。
Perl 5.28
暂时放宽了将特殊字符
{
进行转义的要求,给用户更多时间来修复遗
留代码。
Perl 5.30
则重新开启了这个要求。
所有以上这些量词都可以用另一种统一方式重新书写,我们列在
7-1
中。
7
-
1
:正则表达式量词及其对应的广义形式
匹配次数
元字符
一般化写法
可有可无
? {0,1}
零或多次
* {0,}
一次以上
+ {1,}
至少多少次,不设上限
{3,}
指定重复次数范围
{3,5}
指定可以不匹配的重复次数范围
{0,5}
{,5}(5.34
)
准确的重复次数
{3}
模式分组
我们可以用圆括号
()
将模式字符串分组,所以圆括号也是元字符。
我们知道,量词只作用于它之前的那个字符,像模式
/fred+/
能匹配
freddddddddd
样的字符串,因为量词
+
之前的是字母
d
。如果要匹配整个
fred
的重复次数,就得
用括号把它围起来,写作
/(fre d)+/
,此时量词对应要重复的就是前面这个用括号围
起来的部分,所以能匹配
fredfredfred
这样的字符串。
圆括号还能帮我们在表达式内重复利用匹配到的字符。我们可以用反向引用( ...
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

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036