Preface
1:Introductionc to Regular Expressions
Solving Real Problems
Regular Expressions as a Language
The Filename Analogy
The Language Analogy
The Regular-Expression Frame of Mind
If You Have Some Regular-Expression Experience
Searching Text Files:Egrep
Egrep Metacharacters
Start and End of the Line
Character Classes
Matching Any Character with Dot
Alternation
Ignoring Differences in Capitalization
Word Boundaries
In a Nutshell
Optional Items
Other Quantifiers:Repetition
Parentheses and Backreferences
The Great Escape
Expanding the Foundation
Linguistic Diversification
The Goal of a Regular Expression
A Few More Examples
Regular Expression Nomenclature
Improving on the Status Quo
Summary
Personal Glimpses
3:Extended Introductory Examples
About the Examples
A Short Introductioncto Perl
Matching Text with Regular Expressions
Toward a More Real-World Example
SidecEffects of a Successful Match
Intertwined Regular Expressions
Intermission
Modifying Text with Regular Expressions
Example: FormcLetter
Example:Prettifying a Stock Price
Automated Editing
A Small Mail Utility
Adding Commas to a Number with Lookaround
Text-to-HTML Conversion
That Doubled-Word Thing
3:Overview of Regular Expression Features and Flavors
A Casual Stroll Across the Regex Land scape
The Origins of Regular Expressions
At a Glance
Care and Handling of Regular Expressions
Integrated Handling
Procedural and Object-Oriented Handling
A Search-and-Replace Example
Search and Replace in Other Languages
Care and Handling:Summary
Strings,Character Encodings,and Modes
Strings as Regular Expressions
Character-Encoding Issues
Regex Modes and Match Modes
Common Metacharacters and Features
Character Representations
Character Classes and Class-L1ke Constructs
Anchors and other“Zero-Width Assertions”
Comments and Mode Modifiers
Grouping,Capturing,Conditionals,and Control
Guide to the AdVanced Chapters
4:The Mectanics of Exptession Protessing
Start Your Engines!
Two Kinds of Engines
New Standards
Regex Engine Types
From the Department of Redundancy Department
Testing the Engine Type
Match Basics
About the Examples
Rule l:The Match That Begins Earliest Wirls
Engine Pieces and Parts
Rule 2:The Standard Quantifiers Are Greedy
Regex-Directed Versus Text-Directed
NFA Engine:Regex-Directed
DFA Engine:Text-Directed
First ThOLIghts:NFA and DFA in Comparison
Backtracking.
A Really Crummy Analogy
Two Important Points on Backtracking
Saved States
Backtracking and Gteediness
More About Greediness and Backtracking
Problems of Gteediness.
Multi-Character“Quotes”
Using Lazy Qnantifiers
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
Is Alternation Greedy?
Taking Advantage of ordered Alternation
NFA.DFA.and POSIX
“The Longest.Leftmost”
PoSIX and the Longest-Leftmost Rule
Speed and Efficiency
Summary:NFA and DFA in Comparison
Summary
5:Practical Regex Techniques
Regex Balancing Act
A Few Shon Examples
Continuing With Continuation Lines
Matching an IP Addtess
Working With Filenames
Matching Balanced Sets of Parentheses
Watching Out for Unwanted Matches
Matching Delimited Text
Knowing Your Data and Making Assumptions
Stripping Leading and Trailing Whitespace
HTML-Related Examples
Matching an HTML Tag
Matching an HTML Link
Examining an HTTP URL
Validating a Hostname
P1ucking out a URL in the Real World
Extended Examples
Keeping in Sync With Your Data
Parsing CSV Files
6: Crafting an Efficient Expression
A Sobering Example
A Simple Change-Placing Your Best Foot Forvcard
Efficiencv Ve-rses Correctness
Advancing Further--Localizing the Greediness
RealitV Check
A Global VieW of Backtracking
More Work for a PoSIX NFA
Work Required During a Non-Match
Being More Specific.
A1ternation Can Be Exoensive
Benchmarking
Know What You're Measuring
Benchmarking With Java
Benchmarking With VB.NET
Benchmarking With Python
Benchmarking With Ruby
Benchirlarking With Tcl
Common optimizations
No Free Lurich
Evervone’s Lunch is Dfifetent
The Mechailics of Regex Application
Pre-Application Optimizations
Optimizations With the Transmission
Optimizations of the Regex Itself
Techniques for Faster Expressions
Common Sense Techniques
Expose Literal Text
Expose Anchors
Lazy Versus Greedy:Be Specific
Split Into Multiple Regular Expressions
Mimic Initial-Character DiscriminaCion
use Atomic Grouping and Possessive Quantifiers
Lead the Engine to a Match
Unrolling the Loop
Method 1:Building a Regex From Past Experiences
The Real“Unrolling-the-Loop”Panern
Method 2:A ToD-Down View
Method 3:An Internet Hostname
observations
using Atomic Gtonping and PossessiVe Quantifiers
Short Unrolling Examples
Unrolling C Comments
The Freenowing Regex
A Helping Hand to Guide the Match
A Well-Guided Regex is a Fast Regex
Wrapup
In Summarg:Think!
7:Perl
ReguIar Expressi0128 as a Language Component
Perl’s Greatest Strength
Perl’s Greatest Weakness
Pefl’s Regex Flavor.
Regex operands and Regex Literals
HOW Regex Literals Are Parsed
Regex Modifiers
Regex-Related Perlisms
Expression ConteXt
Dynamic SCOpe and Regex Match Effects
Special Variables Modi6ed by a Match
The qr//operator and Regex objectS
Building and Using Regex objects
Viewing Regex objects
Using Regex objectS for Efficiency
The Match operator
Match’s Regex operand
Specifying the Match Target operand
Diffetent Uses of the MatCh 0perator
Iterative Matching:Scalar Context,with/g
The Match operator's Environmental Relations
The Substitution operator
The Replacement operand
The/e Modifier
Context and Return Value
The Split Operator
Basic Split
Returning Empty Elements
Split’s Special Regex operands
Split’s Match operand with Capturing Parentheses
Fun with Perl Enhancements
Using a Dynamic Regex to Match Nested Pair5
Using the Embedded-Code C01"18truct
Using local jn an Embedded-Code Construct
A Warrling About Embedded Code and my Variables.
Matching Nested Constrtlcts with Enlbedded Code
overloading Regex Literals
Probleros with Regex-Ljteral overJoading
Minlicking Named Capture
Perl Efficiency Issues
“There's More Than one Way to Do It”
Regex Compilation,the/o Modifier qr//,and Efficiency.
Understanding the“Pre-Match”Copy
The Study Function
Benchmarking
Regex Debugging Information
Final Comments
8:Java
Judging a Regex Package
Technical Issues
Social and Political Issues
Obiect Models
A Few AbstraCt obiect Models
Growing Complexity
Packages,Packages,Packages
Why So Many“Perl5”Flavors?
Lies.Damn Lies.and Benchmarks
Recommendations
Sun’s Regex Package
Regex Flavor
using java.util.regex
The Pattern.compile()Factory
The Matcher Obiect
other Pattern Methods
A Quick Look at Jakarta一ORO
ORO’s Perl5Util
A Mini Perl5Util Reference
Using ORO’s Underlying Classes
9: NET
.NET’s Regex Flavor
Additional Comments on the Flavor
Using.NET Regular Expressions
Regex Quickstart
Package overview
Core obiect overview
Core Object Details
Creating Regex Objects
Using Regex Objects
Using Match Objects
Using Group Objects
Static "Convenience" Functions
Regex Caching
Support Functions
Advanced .NET
Regex Assemblies
Matching Nested Constructs
Capture Objects
Index