Mastering Regular Expressions, Second Edition

By Jeffrey E. F. Friedl
July 2002
Pages: 484
ISBN 10: 0-596-00289-0 | ISBN 13: 9780596002893
starstarstarstarstar (5) (Average of 5 Customer Reviews)

This book has been updated—the edition you're requesting is OUT OF PRINT. Please visit the catalog page of the latest edition.

The latest edition is also available on Safari Books Online.

Book description

Regular expressions are an extremely powerful tool for manipulating text and data. They are now standard features in a wide range of languages and popular tools, including Perl, Java, VB.NET and C# (and any language using the .NET Framework), PHP, Python, Ruby, Tcl, MySQL, awk, and Emacs.

If you don't use regular expressions yet, you will discover in this book a whole new world of mastery over your data. If you already use them, you'll appreciate this book's unprecedented detail and breadth of coverage.


Full Description

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 in Perl, 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. If you don't use regular expressions yet, you will discover in this book a whole new world of mastery over your data. If you already use them, you'll appreciate this book's unprecedented detail and breadth of coverage. If you think you know all you need to know about regular expressions, this book is a stunning eye-opener. In spite their wide availability, flexibility, and unparalleled power, regular expressions are frequently underutilized. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. A command of regular expressions is an invaluable skill. Yet what is 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 becoming an expert. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them. Mastering Regular Expressions, Second Edition has been thoroughly updated to include all the 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, entertaining tone that made a complex, dry topic crystal-clear to thousands of programmers, and sprinkled with solutions to complex real-world problems, Mastering Regular Expressions offers a wealth information that you can put to immediate use. Topics include:

  • A comparison of features among different versions of many languages and tools
  • How the regular expression engine works
  • Optimization (major savings available here!)
  • Matching just what you want, but not what you don't want
  • Sections and chapters on individual languages
Post-purchase benefits:

Register your book | Submit Errata | Author's Web site


Browse within this book

| Table of Contents | Index | Sample Chapters | Colophon

Book details

Second Edition: July 2002
ISBN: 0-596-00289-0
Pages: 484
Average Customer Reviews: starstarstarstarstar (5) (Based on 5 Reviews)


Featured customer reviews

Write a Review


Superb book,  November 18 2005
Rating: StarStarStarStarStar
Submitted by Anonymous Reader   [Respond | View]

If you use regular expressions, you'll love this book.

If you don't use regular expressions, this book will open your eyes to a much faster and cleaner way of doing a lot of what you probably struggle with every day.

Not only have I read it through, cover-to-cover, twice - I have permanent bookmarks in the book so I can find the parts I use all the time (the Perl section is particularly useful). Reading this book (and it's companion pocket reference) has saved me literally hours of time on some jobs, and made others possible. Some co-workers made fun of how much I read it - until they needed to understand a regular expression in someone else's code. Now they think it's wonderful.

Some of the best parts include details on the differences between Perl, grep, vi, Java, etc. Very well done. The examples are superb, and the occasional "quiz" lets you make sure you're really understanding what he's talking about. The author also includes references to other pages (instead of making you remember where you saw something


From zero to complete in one day!,  July 10 2004
Rating: StarStarStarStarStar
Submitted by Christopher Nurse   [Respond | View]

This book has transformed the way I plan to write applications. Whereas before I would have had major areas of hardcoded logic, I can now write scripts that can be parsed using regex stuff I have learned from this book.

This makes my applications "soft", it opens up major areas of functionality that can become user customisable, where the customisations can be validated, to bullet proof the application against syntax errors.

In short, think regex, as the author says, open your mind and a whole heap of new possibilities will be yours!


Lucas Gonze photo Amazing,  June 28 2004
Rating: StarStarStarStarStar
Submitted by Lucas Gonze | O'Reilly Author   [Respond | View]

Friedl's obsessiveness is mind blowing, and the result is a remarkable book. He took the trouble to invent new typographic conventions. He constructed, somehow, a compelling narrative flow and informal voice in a book on a very dry topic. The examples illustrate perfectly. The history of regular expressions is comprehensive. Etcetera ad superlativim.

On a practical level I found this book had an impact on my working life. It's useful. But leaving aside the value of advanced regular expressions or of this book in helping you to master them, it is an absurdly well made guide, definitive not just on the topic but also on as an example of technical writing.

Read all reviews


Mastering Regular Expressions, 2nd Edition Review,  February 06 2004
Rating: StarStarStarStarStar
Submitted by George Woolley of Oakland.pm   [Respond | View]



If regular expressions are important to you, get this book.

"Mastering Regular Expressions" is exceptional

both in the scope of what it covers regarding regular expressions

and also in it's thoroughness.

To date this is the most impressive technical book I've read on any subject.

It's a virtuoso performance.

One caveat: parts of the book are quite demanding.

See my longer review for more detail.


Mastering Regular Expressions, 2nd Edition Review,  October 13 2002
Rating: StarStarStarStarStar
Submitted by Larry Bezeau   [Respond | View]

The second edition of Mastering Regular Expressions is

undoubtedly the most thorough and unified coverage of this important

topic. A treatise such as this is appropriate in light of the large

number of programs, both interactive and command line, that use regular

expressions with feature sets that vary from program to program. Many

references on specific languages contain chapters on the use of regular

expressions within the language, but they lack the unifying thrust of

this book. Friedl's book also considers the issue of efficiency in the

use of regular expressions, a topic not normally examined elsewhere.

The book covers regular expressions in general followed by specific

coverage of regular expressions in three languages, Perl, Java, and .net.

A major omission here in my view is JavaScript. The newer versions of

JavaScript have a powerful regular expression capability and, unlike the

other languages considered, JavaScript occurs in a context where there is

no other choice of language, in interactive pages in web browsers. Another

language that gets short-changed is TCL (Tool Command Language) which has

a very powerful and efficient regular expression capability. My own

perference would have been for coverage of these two languages over the

the three chosen by the author.

There is a chapter on solving practical problems but I would have preferred even more on this topic. Little mention is made of utilities

such as sed that depend entirely on regular expressions for their usefulness.

To the author's credit, he does document carefully many of the traps into

which regular expression programmers frequently fall.

Many consider regular expressions to be inelegant but they are

much more concise than the alternatives and are often used where there

is no other reasonable choice. If you find yourself in this situation,

and especially if you are using regular expressions in more than one

language or utility, you will benefit from reading this book. It is

well organized and readable.

Larry Bezeau

University of New Brunswick


Media reviews

"A real tour-de-force of a book which not only covers the mechanics of regexes in extroadiary detail but also talks about efficiency and the use of regexes in Perl, Java, and .NET. . .If you use regular expressions as part of your professional work (even if you already have a good book on whatever language you're programming in) I would strongly recommend this book to you."
--Dr. Chris Brown, "Linux Format," November 2003

"The author does an outstanding job leading the reader from regex novice to master. The book is extremely easy to read and chock full of useful and relevant examples...Regular expressions are valuable tools that every developer should have in their toolbox. 'Mastering Regular Expressions' is the definitive guide to the subject, and an outstanding resource that belongs on every programmer's bookshelf. Ten out of Ten Horseshoes."
--Jason Menard, javaranch.com, March 2003

"An excellent guide to using regular expressions, not only for .Net, but also in Java and Perl...this a valuable book for anyone who needs to master regular expressions."
--Huw Collingbourne, PC Plus, March 2003

"If you use tools like grep, perl, and procmail in your daily life, this book is a good investment both in the money spent and the time working your way through it."
--Jim Secan, The Journal of the Tucson Computer Society, January 2003

"The book is a model of clarity."--PC Plus, February 2003

"For those interested in learning more about regular expressions, I encourage you to obtain a copy of Jeffrey E. F. Friedl's excellent book 'Mastering Regular Expressions.'"
--John Joyce, Scientific & Computing Instrumentation, June 2003

"Friedl, in his 'Mastering Regular Expressions,' takes the reader through an amazing regex journey, probing every nook and cranny, and turning over every rock. I am sure that even the most experienced user of regular expressions will find something new, or a different, or more efficient, solution."--Major Kearny, PC Update, December 2002

"This is an excellent book. If you are at all serious about regular expressions, it is well worth reading. The author really knows his subject and presents what could have been quite a dry subject in a very readable way."
--Kevin Taylor, Northants Linux Users Group, August 2002

"I bought 'Mastering Regular Expressions' for the first time in 1998. I had found it invaluable for learning and using regular expressions (regex) for what I was doing. I considered it to be a classic, and essential to my geek book collection. Imagine my pleasure, then, at finding out that there was now a second edition! I got hold of a copy, and started flipping through it (I seldom read geek books cover to cover - they're references, IMO, not novels). Mind you, this thing is twice the size of the previous version. After I had familiarized myself with its content and structure, it went onto my tool-book shelf right next to the earlier version. Anyone whose programming efforts involve the use of regex will find this book useful, even essential...A 'gotta have' book if you do any heavy regex work, especially in the newer languages or language versions. It is fat, meaty, and was written by a person who uses regex daily in his work"
--Linda Laubenheimer, Linuxchix.org, October 2002


Reviews From Previous Edition
"I've seen the light. Regular expressions always seemed an arcane art to me. I needed to use them in some of my programs--and I wanted to use them for sophisticated text searching--but it was always a struggle and the results were often less than perfect. That was before I read 'Mastering Regular Expressions' by Jeffrey Friedl. This friendly, clear, and useful book lives up to its name. In gradual, easy steps, Jeffrey takes you from beginner to master, and you'll have fun getting there?it may seem to some that mastering regular expressions is something like earning juggling, a skill of limited usefulness. But once you've got this tool under your belt, you'll find uses for it all the time. There's no better way to learn how to use regular expressions than with Jeffrey Friedl's fine book."
--Leo LaPorte, TechTV, July 16, 2002

"It's a definitive reference on the subject and a must-have for serious programmers."--Netsurfer Digest, July 26, 2002

"In 'Mastering Regular Expressions,' Jeffrey Friedal, takes the reader through an amazing regex journey, probing every nook and cranny, and turning over every rock. I am sure that even the most experienced user of regular expressions will find some new or different--and more efficient--solutions."
--Major Keary, Book News, June 2002

"If you have ever used a regular expression or ever wanted to use one, this is the book for you! I really enjoyed reading this book and would recommend it to anyone."
--James Lance, Provo Linux User Group, May 2002

"Let me first recommend Jeffrey Friedel's amazing Mastering Regular Expressions. (O'Reilly). This book contains everything you need to know bout the mysterious regex."
--David Weller, Java Developers Journal Jan 2002

"Jeffrey Freidl's book is not a dummies guide; it demands concentration, but it is a good read in its own right. Even though it is intended for programmers working with regex-supported languages and programming environments, it is a valuable resource for informed lay-readers who would like to explore this fascinating field. As the only reference to the art, it should be on the bookshelf of every programmer and anyone who works with large text files."
--Major Keary, Book News, 2002 No 5

"There's no better resource than Jeffrey Friedl's Mastering Regular Expressions-a great source of sample expressions and detailed explanations of how regular expressions work their magic."
--Jason Snell, MacWorld

"This book is important because regex is so intimidating, and Friedl make it much easier to understand. Many programmers don't use the regex available in their development tools. Chances are, regex will save you a lot of time when you find yourself stuck with a pile of someone else's source code that you need to maintain. If you're just getting started with regex, this book will save you a lot of time (and grief). If you are already using regex, you will extend your ability and understanding."
--Dr. Dobbs Journal

"Mastering Regular Expressions is a superior book. Author Jeffrey Friedl has produces a current, well-written, precise addition to the O'Reilly repertoire, with a volume completely devoted to text and data manipulation. It provides the perfect complement to CGI and Delphi programs and their accompanying texts.... I highly recommend it for anyone and everyone involved with regular expression manipulation."
--Sys Admin Magazine

"A stupendous tour de force of all aspects of pattern matching. With an impeccable eye to the tiniest significant detail, the author covers topics ranging from the subtle differences among NFA, DFA, and POSIX NFA matching behaviors to the practical distinctions of how varying versions of grep, sed, awk, emacs, tcl, python, and perl behave. The author at all times connects theory to practical application of this knowledge in daily programming."
--Tom Christiansen

Hide extended reviews


See larger cover