O'Reilly logo

Perl for Web Site Management by John Callender

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

The Search Pattern

You’ve come to the heart of the regular expression: the search pattern itself. This is the string of text between the opening and closing delimiters (with a substitution expression, between the first and second delimiters). You’ve already seen a fair number of these, so you should have a rough idea of what they look like. Now, though, you’re going to learn how Perl’s regular expression engine actually processes them.

There are two kinds of characters in a regular expression search pattern. First, there are the conventional characters, including all the alphanumeric characters plus the underscore (A-Z, a-z, 0-9, and _), as well as a number of nonalphanumeric characters. All of these conventional characters just match themselves. A regular expression consisting entirely of these characters is easy to understand; it just matches itself. For example, the regular expression /walnuts/ simply matches any string that contains the literal substring walnuts.

Tip

Although it’s not a regular expression metacharacter, strictly speaking, the @ character also might need to be backslashed in order to give its literal meaning, if Perl otherwise might be confused about whether it was an array variable whose contents you were trying to interpolate into the regex pattern.

Besides the conventional characters, there are a number of “unconventional” characters, called metacharacters , which normally don’t match themselves but instead convey some sort of special meaning. The entire ...

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