Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
300
16
练习
16.2
调整上一个练习中的答案,查找名字中有连续
a
a
之间也可以有
n
s
)的蝴蝶种。
16.1.2
贪婪性
+
*
量词是贪婪的,它们会尽可能多地匹配文本。有时,这可能会过多。修改前面
的例子来匹配量词后面的另一个
b
。现在必须至少连续有两个
b
my @strings = < Aba Abba Abbba Ababa >;
for @strings {
put $_, ' ', m/ :i ab+ ba / ?? 'Matched!' !! 'Missed!';
}
第一个
Str
不匹配,因为它不满足一个或多个
b
后面跟着另一个
b
。最后一个
Str
是如此。中间的两个
Str
有足够的
b
来满足模式的这两个部分:
Aba Missed!
Abba Matched!
Abbba Matched!
Ababa Missed!
不过,下面来考虑匹配方法是如何工作的。它看到
b+
时,会尽可能多地匹配
b
。在
Abbba
中,
b+
首先匹配
bbb
。模式的
b+
部分满足。匹配方法移到模式的下一部分,
即另一个
b
。现在文本中再没有任何
b
来满足这一部分了,因为贪心的量词已经匹配
了所有的
b
这个匹配不会失败,因为匹配方法可以使用另一个策略:它可以回溯(
backtrack
)刚
才匹配的量词,要求它放弃一些文本。
b+
需要一个或多个
b
。它匹配两个还是三个并
不重要,因为这都能满足它的要求。在文本中退回一个位置,可以留出一个
b
,使得
下一部分能匹配。一旦退回,它会尝试匹配模式的下一部分。
16.1.3 0
1
?
量词只匹配
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

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002