Tables of Contents for Mastering Regular Expressions
Introduction to Regular Expressions
1
34
Regular Expressions as a Language
4
2
The Regular-Expression Frame of Mind
6
2
If You Have Some Regular-Expression Experience
6
1
Searching Text Files: Egrep
6
2
Start and End of the Line
8
1
Matching Any Character with Dot
11
2
Ignoring Differences in Capitalization
14
1
Other Quantifiers: Repetition
18
2
Parentheses and Backreferences
20
2
Expanding the Foundation
23
10
Linguistic Diversification
23
1
The Goal of a Regular Expression
23
1
Regular Expression Nomenclature
27
3
Improving on the Status Quo
30
2
Extended Introductory Examples
35
48
A Short Introduction to Perl
37
1
Matching Text with Regular Expressions
38
12
Toward a More Real-World Example
40
1
Side Effects of a Successful Match
40
3
Intertwined Regular Expressions
43
6
Modifying Text with Regular Expressions
50
33
Example: Prettifying a Stock Price
51
2
Adding Commas to a Number with Lookaround
59
8
Text-to-HTML Conversion
67
10
That Doubled-Word Thing
77
6
Overview of Regular Expression Features and Flavors
83
60
A Casual Stroll Across the Regex Landscape
85
8
The Origins of Regular Expressions
85
6
Care and Handling of Regular Expressions
93
8
Procedural and Object-Oriented Handling
95
2
A Search-and-Replace Example
97
2
Search and Replace in Other Languages
99
2
Care and Handling: Summary
101
1
Strings, Character Encodings, and Modes
101
11
Strings as Regular Expressions
101
4
Character-Encoding Issues
105
4
Regex Modes and Match Modes
109
3
Common Metacharacters and Features
112
29
Character Representations
114
3
Character Classes and Class-Like Constructs
117
10
Anchors and Other ``Zero-Width Assertions''
127
6
Comments and Mode Modifiers
133
2
Grouping, Capturing, Conditionals, and Control
135
6
Guide to the Advanced Chapters
141
2
The Mechanics of Expression Processing
143
42
From the Department of Redundancy Department
146
1
Testing the Engine Type
146
1
Rule 1: The Match That Begins Earliest Wins
148
1
Engine Pieces and Parts
149
2
Rule 2: The Standard Quantifiers Are Greedy
151
2
Regex-Directed Versus Text-Directed
153
4
NFA Engine: Regex-Directed
153
2
DFA Engine: Text-Directed
155
1
First Thoughts: NFA and DFA in Comparison
156
1
A Really Crummy Analogy
158
1
Two Important Points on Backtracking
159
1
Backtracking and Greediness
162
1
More About Greediness and Backtracking
163
14
Problems of Greediness
164
1
Multi-Character ``Quotes''
165
1
Using Lazy Quantifiers
166
1
Greediness and Laziness Always Favor a Match
167
1
The Essence of Greediness, Laziness, and Backtracking
168
1
Possessive Quantifiers and Atomic Grouping
169
3
Possessive Quantifiers, ?+, *+, ++, and (m,n)+
172
1
The Backtracking of Lookaround
173
1
Is Alternation Greedy?
174
1
Taking Advantage of Ordered Alternation
175
2
``The Longest-Leftmost''
177
1
POSIX and the Longest-Leftmost Rule
178
1
Summary: NFA and DFA in Comparison
180
3
Practical Regex Techniques
185
36
Practical Regex Balancing Act
186
1
A Few Short Examples
186
14
Continuing with Continuation Lines
186
1
Matching an IP Address
187
3
Working with Filenames
190
3
Matching Balanced Sets of Parentheses
193
1
Watching Out for Unwanted Matches
194
2
Matching Delimited Text
196
2
Knowing Your Data and Making Assumptions
198
1
Stripping Leading and Trailing Whitespace
199
1
HTML-Related Examples
200
8
Matching an HTML Link
201
2
Examining an HTTP URL
203
1
Validating a Hostname
203
2
Plucking Out a URL in the Real World
205
3
Keeping in Sync with Your Data
208
4
Crafting an Efficient Expression
221
62
A Simple Change-Placing Your Best Foot Forward
223
1
Efficiency Verses Correctness
223
2
Advancing Further-Localizing the Greediness
225
1
A Global View of Backtracking
228
4
More Work for a POSIX NFA
229
1
Work Required During a Non-Match
230
1
Alternation Can Be Expensive
231
1
Know What You're Measuring
234
1
Benchmarking with Java
234
2
Benchmarking with VB.NET
236
1
Benchmarking with Python
237
1
Benchmarking with Ruby
238
1
Benchmarking with Tcl
239
1
Common Optimizations
239
13
Everyone's Lunch is Different
240
1
The Mechanics of Regex Application
241
1
Pre-Application Optimizations
242
3
Optimizations with the Transmission
245
2
Optimizations of the Regex Itself
247
5
Techniques for Faster Expressions
252
9
Common Sense Techniques
254
1
Lazy Versus Greedy: Be Specific
256
1
Split Into Multiple Regular Expressions
257
1
Mimic Initial-Character Discrimination
258
1
Use Atomic Grouping and Possessive Quantifiers
259
1
Lead the Engine to a Match
260
1
Method 1: Building a Regex From Past Experiences
262
1
The Real ``Unrolling-the-Loop'' Pattern
263
3
Method 2: A Top-Down View
266
1
Method 3: An Internet Hostname
267
1
Using Atomic Grouping and Possessive Quantifiers
268
2
Short Unrolling Examples
270
2
The Freeflowing Regex
277
4
A Helping Hand to Guide the Match
277
2
A Well-Guided Regex is a Fast Regex
279
1
Regular Expressions as a Language Component
285
1
Perl's Greatest Strength
286
1
Perl's Greatest Weakness
286
1
Regex Operands and Regex Literals
288
4
How Regex Literals Are Parsed
292
1
Regex-Related Perlisms
293
10
Dynamic Scope and Regex Match Effects
295
4
Special Variables Modified by a Match
299
4
The qr/-/ Operator and Regex Objects
303
3
Building and Using Regex Objects
303
2
Viewing Regex Objects
305
1
Using Regex Objects for Efficiency
306
1
Match's Regex Operand
307
1
Specifying the Match Target Operand
308
1
Different Uses of the Match Operator
309
3
Iterative Matching: Scalar Context, with /g
312
4
The Match Operator's Environmental Relations
316
2
The Substitution Operator
318
3
The Replacement Operand
319
1
Context and Return Value
321
1
Returning Empty Elements
324
1
Split's Special Regex Operands
325
1
Split's Match Operand with Capturing Parentheses
326
1
Fun with Perl Enhancements
326
21
Using a Dynamic Regex to Match Nested Pairs
328
3
Using the Embedded-Code Construct
331
4
Using local in an Embedded-Code Construct
335
3
A Warning About Embedded Code and my Variables
338
2
Matching Nested Constructs with Embedded Code
340
1
Overloading Regex Literals
341
3
Problems with Regex-Literal Overloading
344
1
Mimicking Named Capture
344
3
Perl Efficiency Issues
347
16
``There's More Than One Way to Do It''
348
1
Regex Compilation, the /o Modifier, qr/.../, and Efficiency
348
7
Understanding the ``Pre-Match'' Copy
355
4
Regex Debugging Information
361
2
Judging a Regex Package
366
2
Social and Political Issues
367
1
A Few Abstract Object Models
368
4
Packages, Packages, Packages
372
6
Why So Many ``Perl5'' Flavors?
375
1
Lies, Damn Lies, and Benchmarks
375
2
Using java.util.regex
381
2
The Pattern.compile () Factory
383
1
Other Pattern Methods
390
2
A Quick Look at Jakarta-ORO
392
7
A Mini Perl5Util Reference
393
4
Using ORO's Underlying Classes
397
2
Additional Comments on the Flavor
402
5
Using .NET Regular Expressions
407
5
Creating Regex Objects
413
2
Static ``Convenience'' Functions
425
1
Matching Nested Constructs
430
1