作者:empty 页数:780 出版社:empty |
Nutshell Handbook and the Nutshell Handbook logo are registered trademarksand The Java Series is a trademark of O'Reilly&Associates, Inc.Many of the designations used by manufacturers and sellers to distinguish theirproducts are claimed as trademarks.Where those designations appear in thisbook, and O'Reilly&Associates, Inc.was aware of a trademark claim, thedesignations have been printed in caps or initial capsWhile every precaution has been taken in the preparation of this book, thepublisher assumes no responsibility for errors or omissions, or for damagesresulting from the use of the information contained herein.
Solving Real Problems
RegularExpression sasa Language
The Filename Analogy
The Language Analogy
The Regular-Expression Frame of Mind
Searching Text Files:Egrep
Egrep Metacharacters
Start and End of the Line
Character Classes
Matching Any Character-Dot
Alternation
Word Boundaries
In a Nutshell
Other Quantifiers:Repetition
Linguistic Diversification
A Short Introduction to Perl
Ignoring Differences in Capitalization
Parentheses and Back references
The Great Escape
Expanding the Foundation
The Goal of a RegularExpression
A Few More Examples
RegularExpression Nomenclature
Improving on the Status Quo
Summary
Personal Glimpses
About the Examples
Matching Text with Regular Expressions
Toward a More Real-World Example
SideEffects of a Successful Match
Intertwined Regular Expressions
Intermission
Modifying Text with Regular Expressions
Automated Editing
A Small Mail Utility
That Doubled-Word Thing
A Casual Stroll Across the Regex Landscape
The World According to Grep
The Times They Area Changin'
At a Glance
POSIX
Care and Handling of Regular Expressions
Doing Something with the Matched Text
Care and Handling:Summary
Identifying a Regex
Other Examples
Engines and Chrome Finish
Chrome and Appearances
Engines and Drivers
Common Metacharacters
Character Shorthands
Strings as RegularExpression
Class Shorthands, Dot, and Character Classes
Anchoring
Grouping and Retrieving
Quantifiers
Alternation
Guide to the Advanced Chapters
Tool-Speci ic Information
Start Your Engines!
Two Kinds of Engines
New Standards
Regex Engine Types
From the Department of Redundancy Department
Match Basics
About the Examples
Rule I:The Earliest Match Wins
The Transmission and the Bump-Along
Rule2:SomeMetacharactersAreGreedy
Uses for Non-Greedy Alternation
Engine Pieces and Parts
Regex-Directed vs.Text-Directed
NFAEngine:Regex-Directed
DFAEngine:Text-Directed
The Mysteries of Life Revealed
Backtracking
A Really Crummy Analogy
Two Important Points on Backtracking
Saved States
Backtracking and Greediness
More About Greediness
Problems of Greediness
Multi-Character Quotes
Laziness?
Greediness Always Favors a Match
Is Alternation Greedy?
Greedy Alternation in Perspective
Character Classes vs.Alternation
NFA, DFA, and POSIX
'The Longest-Lef most
POSIX and the Longest-Leftmost Rule
Speed and Efficiency
DFA and NFA in Comparison
Practical Regex Techniques
Contributing Factors
Be Specific
Difficulties and Impossibilities
Watching Out for Unwanted Matches.
Matching Delimited Text
Knowing Your Data and Making Assumptions
Additional Greedy Examples
Summary
Match Mechanics Summary
Some Practical Effects of Match Mechanics
5:Crafting a RegularExpression
A Sobering Example
A Simple Change-Placing Your Best Foot Forward
More Advanced-Localizing the Greediness
RealityCheck
A Global View of Backtracking
More Work for a POSIX NFA
Work Required During aN on-Match.
Being More Specific
Alternation Can Be Expensive
A Strong Lead
The Impact of Parentheses
First-Character Discrimination
Traditional N FAvs.POSIX NFA Testing
Internal Optimization
Fixed-String Check
Simple Repetition
Needless Small Quantifiers
Length Cognizance
Match Cognizance
Need Cognizance
String/Line Anchors
Compile Caching
Testing the Engine Type
Basic N FAvs.DFA Testing
Unrolling the Loop
Method1:BuildingaRegexFromPastExperiences
The Real Unrolling the Loop Pattern.
Method2:ATop-DownView
Method3:AQuotedInternetHostname
Observations
Unrolling C Comments
Regex Headaches
A Naive View
Unrolling the CLoop
The Free flowing Regex
A Helping Hand to Guide the Match.
A Well-Guided Regex is a Fast Regex.
Wrapup
Think!
The Many Twists and Turns of Optimizations
Questions You Should Be Asking
Something as Simple as Grep
In This Chapter
Awk
Differences Among Awk Regex Flavors
Awk Regex Functions and Operators
Tel
Tel Regex Operands
7:Perl Regular Expressions
Using Tel Regular Expressions
Tel Regex Optimizations
GNU Emacs
Emacs Strings as Regular Expressions
Emacs's Regex Flavor
Emacs Match Results
Benchmarking in Emacs
Emacs Regex Optimizations
The Perl Way
RegularExpression sasa Language Component
Perl's Greatest Strength
Perl's Greatest Weakness
A Chapter, a Chicken, and The Perl Way
An Introductory Example:Parsing CSV Text
Regular Expressions and The Perl Way
Perl Unleashed
Regex-Related Perlis ms
Expression Context
Dynamic Scope and Regex Match Effects
Special Variables Modified by a Match
Quantifiers-Greedy and Lazy
Convenient Shorthands and Other Notations
204
Page x
204
207
208
210
210
211
217
219
225
225
227
232
236
240
24l
243
245
Double quot ish Processing and Variable Interpolation
Perl's Regex Flavor
Grouping
String Anchors
Multi-Match Anchor
Word Anchors
Character Classes
Modification with Q and Friends:True Lies
The Match Operator
246
247
249
250
251
252
254
255
255
257
258
259
259
259
261
262
264
264
265
266
268
273
Match-Operand Delimiters
Match Modifiers
Basic Split
Scalar-Context