O'Reilly logo

Learning Perl, 6th Edition by Tom Phoenix, Randal L. Schwartz, brian d foy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. In the World of Regular Expressions

Perl has many features that set it apart from other languages. Of all those features, one of the most important is its strong support for regular expressions. These allow fast, flexible, and reliable string handling.

But that power comes at a price. Regular expressions are actually tiny programs in their own special language, built inside Perl. (Yes, you’re about to learn another programming language![188] Fortunately, it’s a simple one.) So in this chapter, you’ll visit the world of regular expressions, where (mostly) you can forget about the world of Perl. Then, in the next chapter, we’ll show you where this world fits into Perl’s world.

Regular expressions aren’t merely part of Perl; they’re also found in sed and awk, procmail, grep, most programmers’ text editors such as vi and emacs, and even in more esoteric places. If you’ve seen some of these already, you’re ahead of the game. Keep watching, and you’ll see many more tools that use or support regular expressions, such as search engines on the Web, email clients, and others. The bad news is that everybody’s regular expressions have slightly different syntax, so you may need to learn to include or omit an occasional backslash.

What Are Regular Expressions?

A regular expression, often called a pattern in Perl, is a template that either matches or doesn’t match a given string.[189] That is, there are an infinite number of possible text strings; a given pattern divides that infinite set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required