A Summary of Options and Escapes

Throughout this lesson, I've been mentioning various options you can use with patterns, as well as a number of the special escapes that you can use inside patterns.

Table 10.1 shows the options you can tag onto the end of the pattern matching expression (m// or just //) as well as those that can be used with the substitution expression (s///).

Note

I haven't described all these options in this lesson. You'll learn about some of these in “Going Deeper,” later in this chapter, but you might also want to check out the perlre man page for more information on any options that look interesting.


Table 10.1. Pattern Matching and Substitution Options
Option Use
g Match all occurrences (not just one)
i Match both upper and lowercase
m Use ^ and $ for newlines
o Interpolate pattern once (for better efficiency)
s Dot (.) includes newlines
x Extend regular expressions (can include comments and whitespace)
e Evaluate replacement as a Perl expression (s/// substitution only)

Table 10.2 contains the special escapes that can be used inside regular expressions, in addition to the usual string escapes such as and , and backslashes used to turn metacharacters into regular characters.

Table 10.2. Pattern Matching Escapes
Escape Use
A Beginning of string
 End of string
w Word character
W Non-word character
 Word boundary
B Non-word boundary
s Whitespace character
S Non-whitespace character
d Digit
D Non-digit
Q Escape all special characters
E End Q sequence

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset