Mastering Regular Expressions

Front Cover
"O'Reilly Media, Inc.", 2002 - Computers - 460 pages

Regular expressions are an extremely powerful tool for manipulating text and data.They have spread like wildfire in recent years, now offered as standard features inPerl, Java, VB.NET and C# (and any language using the .NET Framework), PHP, Python, Ruby, Tcl, MySQL, awk, Emacs, and many other popular tools and languages. Ifyou don't use regular expressions yet, you will discover in this book a whole newworld of mastery over your data. If you already use them, you'll appreciate thisbook's unprecedented detail and breadth of coverage. If you think you know all youneed to know about regular expressions, this book is a stunning eye-opener. In spitetheir wide availability, flexibility, and unparalleled power, regular expressions arefrequently underutilized. Regular expressions allow you to code complex and subtletext processing that you never imagined could be automated. Regular expressions cansave you time and aggravation. They can be used to craft elegant solutions to a widerange of problems. A command of regular expressions is an invaluable skill. Yet whatis power in the hands of an expert can be fraught with peril for the unwary.

"Mastering Regular Expressions" will help you navigate the minefield to becomingan expert. Once you've mastered regular expressions, they'll become an invaluablepart of your toolkit. You will wonder how you ever got by without them. "MasteringRegular Expressions," Second Edition has been thoroughly updated to include allthe new features of Perl 5.8, as well as several other languages, including Java, VB.NET, C#, Python, JavaScript, Tcl, and Ruby. Written in the lucid, entertainingtone that made a complex, dry topic crystal-clear to thousands of programmers, andsprinkled with solutions to complex real-world problems, "Mastering RegularExpressions" offers a wealth information that you can put to immediate use. Topicsinclude: A comparison of features among different versions of many languagesand toolsHow the regular expression engine worksOptimization (major savings available here!)Matching just what you want, but not what you don't wantSections and chapters on individual languages

 

Selected pages

Contents

Preface
xv
Introduction to Regular Expressions
1
Solving Real Problems
2
Regular Expressions as a Language
4
The RegularExpression Frame of Mind
6
Egrep Metacharacters
8
Expanding the Foundation
23
Personal Glimpses
33
Benchmarking
232
Common Optimizations
239
Techniques for Faster Expressions
252
Unrolling the Loop
261
The Freeflowing Regex
277
Think
281
Perl
283
Regular Expressions as a Language Component
285

Extended Introductory Examples
35
About the Examples
36
Matching Text with Regular Expressions
38
Modifying Text with Regular Expressions
50
Overview of Regular Expression Features and Flavors
83
A Casual Stroll Across the Regex Landscape
85
Care and Handling of Regular Expressions
93
Strings Character Encodings and Modes
101
Common Metacharacters and Features
112
Guide to the Advanced Chapters
141
The Mechanics of Expression Processing
143
Match Basics
147
RegexDirected Versus TextDirected
153
Backtracking
157
More About Greediness and Backtracking
163
NFA DFA and POSIX
177
Summary
183
Practical Regex Techniques
185
Regex Balancing Act
186
HTMLRelated Examples
200
Extended Examples
208
Crafting an Efficient Expression
221
A Sobering Example
222
A Global View of Backtracking
228
Perls Regex Flavor
286
RegexRelated Perlisms
293
The qr Operator and Regex Objects
303
The Match Operator
306
The Substitution Operator
318
The Split Operator
321
Fun with Perl Enhancements
326
Perl Efficiency Issues
347
Final Comments
363
Java
365
Judging a Regex Package
366
Object Models
368
Packages Packages Packages
372
Suns Regex Package
378
A Quick Look at JakartaORO
392
NET
399
NETs Regex Flavor
400
Using NET Regular Expressions
407
Core Object Details
412
Static Convenience Functions
425
Support Functions
426
Advanced NET
427
Index
433
Copyright

Other editions - View all

Common terms and phrases

About the author (2002)

Jeffrey Friedl was raised in the countryside of Rootstown, Ohio, and had aspirations of being an astronomer until one day he noticed a TRS-80 Model I sitting unused in the corner of the chem lab (bristling with a full 16K of RAM, no less). He eventually began using Unix (and regular expressions) in 1980, and earned degrees in Computer Science from Kent (BS) and the University of New Hampshire (MS). He did kernel development for Omron Corporation in Kyoto, Japan for eight years before moving in 1997 to Silicon Valley to apply his regular-expression know-how to financial news and data for a little-known company called "Yahoo!" When faced with the daunting task of filling his copious free time, Jeffrey enjoys playing Ultimate Frisbee and basketball with friends at Yahoo!, programming his house, and feeding the squirrels and jays in his back yard. He also enjoys spending time with his wife Fumie, and preparing for the Fall 2002 release of their first "software project" together.