Skip to Content
Learning Perl, 7th Edition
book

Learning Perl, 7th Edition

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2016
Beginner
391 pages
10h 38m
English
O'Reilly Media, Inc.
Content preview from Learning Perl, 7th Edition

Chapter 7. Regular Expressions

Perl has strong support for regular expressions, or regexes for short. This mini-language within Perl is a tight and powerful way to describe a family of strings that can match a pattern. It’s one of the features that has made Perl so popular.

Today many languages have some sort of access to these powerful tools (perhaps as something called “Perl-Compatible Regular Expressions,” or PCRE), but Perl is still out in front of most them in its power and expressivity.

In the next three chapters, we will show you most of the regex features that you’ll use in most programs. In this chapter, we’ll show you the basics of the regular expression syntax. In Chapter 8, we show you the match operator and more sophisticated ways of employing patterns. Finally, in Chapter 9, we show you ways to use patterns to modify text.

Regexes will probably become one of your favorite parts of the language, at least for a while. But, since regular expressions are tight and compact, they may also frustrate you to no end until you get used to them. That’s normal. As you go through these chapters, try the examples as you read them. The more complex patterns build on what you’ve read earlier.

Sequences

Perl’s regular expressions either match a string or they don’t. There is no such thing as a partial match. And, Perl doesn’t look for a best match. Instead, it matches the leftmost, longest substring that satisfies the pattern.

Note

Some regular expression engines in other languages work differently, ...

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.
Start your free trial

You might also like

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Perl One-Liners

Perl One-Liners

Peteris Krumins
Learning Perl, 8th Edition

Learning Perl, 8th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant

Publisher Resources

ISBN: 9781491954317Errata Page