1: Introduction to Regular Expressions
Regular Expressions as a Language
The Regular-Expression Frame of Mind
If You Have Some Regular-Expression Experience
Matching Any Character with Dot
Ignoring Differences in Capitalization
Parentheses and Backreferences
The Goal of a Regular Expression
Regular Expression Nomenclature
2: Extended Introductory Examples
Matching Text with Regular Expressions
Toward a More Real-World Example
Side Effects of a Successful Match
Intertwined Regular Expressions
Modifying Text with Regular Expressions
Example: Prettifying a Stock Price
Adding Commas to a Number with Lookaround
3: Overview of Regular Expression Features and Flavors
A Casual Stroll Across the Regex Landscape
The Origins of Regular Expressions
Care and Handling of Regular Expressions
Procedural and Object-Oriented Handling
Search and Replace in Other Languages
Strings, Character Encodings, and Modes
Strings as Regular Expressions
Common Metacharacters and Features
Character Classes and Class-Like Constructs
Anchors and Other “Zero-Width Assertions”
Grouping, Capturing, Conditionals, and Control
Guide to the Advanced Chapters
4: The Mechanics of Expression Processing
From the Department of Redundancy Department
Rule 1: The Match That Begins Earliest Wins
Rule 2: The Standard Quantifiers Are Greedy
Regex-Directed Versus Text-Directed
First Thoughts: NFA and DFA in Comparison
Two Important Points on Backtracking
More About Greediness and Backtracking
Greediness and Laziness Always Favor a Match
The Essence of Greediness, Laziness, and Backtracking
Possessive Quantifiers and Atomic Grouping
Possessive Quantifiers, ?+, *+, ++, and {m,n}+
The Backtracking of Lookaround
Taking Advantage of Ordered Alternation
POSIX and the Longest-Leftmost Rule
Summary: NFA and DFA in Comparison
Continuing with Continuation Lines
Matching Balanced Sets of Parentheses
Watching Out for Unwanted Matches
Knowing Your Data and Making Assumptions
Stripping Leading and Trailing Whitespace
Plucking Out a URL in the Real World
Keeping in Sync with Your Data
6: Crafting an Efficient Expression
A Simple Change—Placing Your Best Foot Forward
Advancing Further—Localizing the Greediness
Work Required During a Non-Match
The Mechanics of Regex Application
Optimizations with the Transmission
Optimizations of the Regex Itself
Techniques for Faster Expressions
Lazy Versus Greedy: Be Specific
Split Into Multiple Regular Expressions
Mimic Initial-Character Discrimination
Use Atomic Grouping and Possessive Quantifiers
Method 1: Building a Regex From Past Experiences
The Real “Unrolling-the-Loop” Pattern
Method 3: An Internet Hostname
Using Atomic Grouping and Possessive Quantifiers
A Helping Hand to Guide the Match
A Well-Guided Regex is a Fast Regex
Regular Expressions as a Language Component
Regex Operands and Regex Literals
Dynamic Scope and Regex Match Effects
Special Variables Modified by a Match
The qr/···/ Operator and Regex Objects
Building and Using Regex Objects
Using Regex Objects for Efficiency
Specifying the Match Target Operand
Different Uses of the Match Operator
Iterative Matching: Scalar Context, with /g
The Match Operator’s Environmental Relations
Split’s Special Regex Operands
Split’s Match Operand with Capturing Parentheses
Using a Dynamic Regex to Match Nested Pairs
Using the Embedded-Code Construct
Using local in an Embedded-Code Construct
A Warning About Embedded Code and my Variables
Matching Nested Constructs with Embedded Code
Problems with Regex-Literal Overloading
“There’s More Than One Way to Do It”
Regex Compilation, the /o Modifier, qr/···/, and Efficiency
Understanding the “Pre-Match” Copy
Java Support for \p{···} and \P{···}
Methods for Building a Scanner
Pattern’s split Method, with One Argument
Pattern’s split Method, with Two Arguments
Adding Width and Height Attributes to Image Tags
Validating HTML with Multiple Patterns Per Matcher
Parsing Comma-Separated Values (CSV) Text
Differences Between 1.4.2 and 1.5.0
Differences Between 1.5.0 and 1.6
Additional Comments on the Flavor
Using .NET Regular Expressions
Static “Convenience” Functions
Syntax-Checking an Unknown Pattern Argument
Syntax-Checking an Unknown Regex
Matching Text with Nested Parentheses
No Backtracking Into Recursion
Matching a Set of Nested Parentheses
The S Pattern Modifier: “Study”