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 ...
Get Perl for Web Site Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.