Jump to ratings and reviews
Rate this book

Mastering Regular Expressions

Rate this book
Supported by tools, languages, and environments ranging from Emacs to VB .NET, regular expressions let you streamline text and data searching and processing. Whether you're new to their advantages or out to boost your expertise, here's how to add them to your arsenal.

496 pages, Paperback

First published January 8, 1997

283 people are currently reading
2465 people want to read

About the author

Jeffrey E.F. Friedl

1 book13 followers
Jeffrey worked for Omron Tateishi Denki (1989-1997) and Yahoo! Finance (1997-2005), but now lives in Kyoto, Japan with his family.

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
904 (43%)
4 stars
758 (36%)
3 stars
338 (16%)
2 stars
69 (3%)
1 star
28 (1%)
Displaying 1 - 30 of 80 reviews
Profile Image for briz.
Author 6 books75 followers
August 4, 2017
Mwah, mwah! Thank you, Jeff Friedl, for finally - FINALLY - demystifying this most crucial of meta-programming skills: regular expressions. I had tried online tutorials, videos, even a retro bash game, this and that. Nothing ever helped. This did. FINALLY. FINALLY!

So I didn't "read" the whole book, but whatever, the second half is reference material for languages I never use nor plan to use (Perl, PHP, etc.). Honestly, the first 2-3 chapters were sufficient; once he got into the guts of different regex languages, I felt like I was teleported back to 1983 Bay Area, sitting next to Steve Wozniak as he pecked at his clackety-clack keyboard and wrote the original BSD man pages. Awwww myyyannn, I just did `man grep` to double-check my facts and DAMMIT the last update to the grep man page was 2010!!!! Way to kill my joke, Unix.

Henyyyway. Highly recommended, though YMMV - people learn in diff ways. I had been daunted by regexes since the 2009 Stata days, and I just *WISH* I had had this then.

For my future reference (and yours), a muscle must be exercised, and here are some regex games:
- https://alf.nu/RegexGolf
- https://regexcrossword.com/
- https://www.hackerrank.com/dashboard has a bunch
- https://github.com/bchartoff/regexcal... (the bash game)
Profile Image for Igor Tsinman.
32 reviews34 followers
June 15, 2012
Mastering Regular Expressions by Jeffrey E.F. Friedl это замечательная книга/учебник. Всем программистам иметь/читать обязательно. UNIX/Linux программистам я рекомендую прочитать эту книгу раз десять (т.е. выучить наизусть).

Без навыков написания regex очень сложно (практически невозможно) использовать sed, awk, shell, perl, python, etc. А без этого работать на UNIX системах не получится (исключение из этого правило это Java-Java программеры, которым в принципе все равно на какой системе работать, лишь бы было окошко Eclipse)
Profile Image for Jesse Houwing.
Author 2 books4 followers
November 9, 2013
If you ever need to dive deeply into regular expressions, then this is the book to read. It doesn't just cover syntax, but dived deeply into state machines, optimizations and the way the engine's are generally implemented.

This book, however, doesn't tell you how to use each different dialect of Regex out there and some of the things the book explains might not be true for your regex engine of choice. I've used it a lot in conjunction with the Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET and that kind of fills that void (though the second edition contains a few errors in the syntax examples for .NET code, which is my engine of choice normally.
Profile Image for Piper.
5 reviews
July 28, 2019
Loved it. Pretty much love everything.
Profile Image for Mihai.
186 reviews17 followers
December 7, 2021
One of the best I've read on the subject
Profile Image for David.
6 reviews1 follower
December 10, 2021
Before O'Reilly started trying to be hip and cool and coining terms like "Web 2.0", they used to write books that didn't suck. This is one of them.

Think you know regular expressions? This book isn't a simple introduction that fades out somewhere near character classes. It's called "Mastering Regular Expressions", and that indeed is it's intent.
Profile Image for Abhishek Kumar.
13 reviews1 follower
July 25, 2017
Giving this book a perfect rating because this enables you to think in terms of building a correct and efficient regular expression and does that with a great correctness and efficiency. Had a doubt in a section of book, emailed author and he replied promptly! It discussed in great deal the mechanism of the engine and which helps to think in terms of regular expression.
Profile Image for Nick Black.
Author 2 books878 followers
May 19, 2008
I would have expected both more theory and detail regarding implementation from such a book.
Profile Image for Illia.
210 reviews4 followers
October 3, 2016
Теперь я можу навіть розмовлятьи регулярними виразами. :)
Profile Image for Kinan Diraneyya.
155 reviews11 followers
February 3, 2023
You will only have one hand free while reading Mastering Regular Expressions because Jeffrey Friedl will take you by your other hand and lead you through everything there is to know about regular expressions.

You will see your mistakes corrected as you make them, you will ask questions and find their answers at the end of the page, and when Jeffrey explains concepts in Ruby, right before you open your mouth to tell him that you only code in Java, he will point to the next page where you will find the same code written in it.

The first couple of chapters are an introduction to the subject, with a few examples that increase in complexity as you go on. By the end of the third chapter (only a third of the book), you would already know every possible RegEx mechanic.

However, throughout all that, you will come across notes on many examples, explaining that they will be revisited in later chapters to correct a few mistakes or be made more efficient, with page numbers referencing where to ease the book's navigation.

But before beginning with the advanced techniques, Jeffrey takes a break from the subject of usage to explain the inner workings of RegEx engines. Without showing any code, you are shown how engines go about parsing expressions and exactly why some patterns perform worse than others in certain situations.

By the time you begin with the advanced techniques, you will find yourself equipped enough to understand the reason behind each of them. And I would like to believe that at that point, like myself, you will bow to the brilliance of Jeffrey E.F. Friedl and the way he explains concepts.

The last few chapters each discuss regular expressions for certain languages. Like most readers, I skipped the ones that didn't concern me (Ruby and .NET). I must say that even there, I was still surprised to find extremely specific tips, signifying the time spent using and researching these libraries for the sole purpose of writing these sections.

Mastering Regular Expressions is a book made with great brilliance and dedication, it provides a fantastic reading experience with its examples and references, and I doubt you would find any better book on the subject.
Profile Image for Jean Tessier.
163 reviews32 followers
June 8, 2018
Good, practical guide for understanding how regular expressions work without going into the deep stuff about automata theory. I was hoping for more practical coverage of different syntaxes and more examples rewritten in each, especially Emacs. Still, quite good about regular expressions in general.
But if you want to learn a particular flavor, you will need something more focused on that language or tool.

There is a more recent edition published in 2002 with 150 additional pages that I haven't looked at.
Profile Image for Bhaskar Chowdhury.
33 reviews3 followers
November 28, 2020
Brain draining ...considering kind of gray cells I have between the ears. But, not all lost ..most was very known to me from other sources and over long time practice ...little bit here and there ...so it was not a unfamiliar story(if you think in that way of purely technical book) .

Anyway, learn loads of stuff , useful ...but I am not yet sure how much I can remember and use ...probably lean on to this time and again.

Highly recommended, if you want to deal with complex stuff and want pinpoint accuracy of the applicable things by knowing intricacies of inner working of RegEx(yes, in the tech world we called this subject by this short name!, convenient) .

Valued!!
Profile Image for Joseph.
33 reviews8 followers
April 25, 2018
To be upfront, I did not read the book cover to cover - I stuck to the chapters that were relevant to me and what I needed in an immediate sense. That being said, the content in those chapters was invaluable.
29 reviews
October 26, 2021
A good introduction and reference book on regular expressions. I've read this book as some who knows and has used regular expressions but has found its use to be difficult. This book is a much more in depth learning tool than the 5 min explanations you will find online.
Profile Image for Joe.
42 reviews9 followers
November 12, 2017
If you're a programmer of any kind you should know regular expressions. And if you want to learn regular expressions, this is the bible. That's all there is to it.
Profile Image for Doug Wolf.
77 reviews
February 23, 2019
This book really cleared a lot of the fog about regular expressions and the power they unlock.
Profile Image for Franklin.
4 reviews15 followers
May 22, 2019
Informative - Initimadating - Brilliant
Profile Image for Ranranzi.
25 reviews3 followers
November 26, 2019
I just read the first six chapters to solve a quiz in An Introduction To Programming In Emacs Lisp.

I still read this book everytime I need to write expressions.
66 reviews2 followers
January 31, 2021
A superb book on regular expressions. It taught me more than most other books I read on the topic.
372 reviews
Read
December 17, 2024
""
This entire review has been hidden because of spoilers.
Profile Image for Dang-Khoa Le Tan.
41 reviews14 followers
did-not-finish
February 1, 2025
Chapter 4 is dragged for too long and becomes unbearable. I am no longer interested in what it was telling ...
Maybe the best I get from the book is lookaround, lazy quantifier and Perl coolness.
Profile Image for Sergey Machulskis.
103 reviews9 followers
March 14, 2020
The book cleared a lot of fog in my understanding of regular expressions. I knew they're based on finite automata theory (from this excellent book, which I highly recommend). I thought DFAs and NFAs are equivalent in power and different regular expression engines just implement their own translations of regexes to those NFA or DFA forms. It turned out, modern regular expressions much, much more powerful than NFAs. This book explains why. As a side effect, it helps to understand how to craft correct and efficient regular expression. Even for the POSIX NFA engine.

I wasn't sure about the interaction of regular expressions with language around them. This includes escaping rules, regex engine types and so on. There's a lot of examples in different languages so you can really feel the difference between regex flavors.

I didn't read the whole book, the second half is about guts of languages I never use nor plan to use (Perl, PHP, .Net).

-1 star for silly examples. Who's gonna parse HTML or even URLs using regular expressions? It's a minefield.
Profile Image for Rick Strong.
23 reviews7 followers
June 9, 2016
I'm currently reading this book, not done yet, but I'll rate it 5 stars anyway for its usefulness. Regex, which provides a formal way to express text search patterns, is one of the things I always promised to learn properly, since the need for it - finding and replacing text - pops up so often in software development. In my current assignment I've had to use it on a VERY regular basis, and this prompted me to sit down with this volume and go through it front to back.

The first part of the book deals with regex in a very general way; later on it gets into implementation-specific issues, the mechanics of how it actually works, and performance considerations. I've only read through the first parts, and already it has been very useful. I'm very much looking forward to the rest.

At this point in the book, the author has provided examples using egrep (a software tool that searches text using regex) and Perl, which has very comprehensive support for it. Both of these are available online at no additional cost, and if you are running OS X or Linux you probably already have Perl installed.

I have actually found it even more useful to keep one of the online regex testing pages (https://regex101.com is a good one) open while reading, which makes it easy to try things out as I'm reading. I should mention that I purchased the Kindle edition, so that I could stay in the same environment for reading and trying out code examples. Very highly recommended.

Update: I'm going to say I'm done with this, even though I may not have read every page. It's a good reference, and has proven useful several times. Still very highly recommended.
Profile Image for Chris Austin.
76 reviews10 followers
February 18, 2022
I read the first edition in 1999 and found it incredibly useful since it helped me learn to think in regex, building efficient and accurate expressions instead of hacking away until it seemed to work. It also helped me build maintainable patterns that others would be able to read and grok.

I'm reading the 3rd edition now as a refresher, and to revisit the way regex engines are constructed since I see these problems differently now.

For the 3rd edition I would have preferred a different language than Perl for the introduction. I know Perl very well, have written fun JAPH scripts, attended a Perl conference, and brought engineering discipline to the systems I wrote with it (long ago)... but it's not something I'd consider modern or intuitive. Learning about $/, <>, and interpolation of @ aren't really necessary for learning regular expressions. It is a good choice for some reasons though, especially the /x modifier, which improves readability.

Overall I give it a 4. It would be a 5 for the regex portions, though there's a bit too much filler narrative that I skim. The print quality for my copy isn't what I'd expect from O'Reilly, so I prefer reading the ebook version.
Profile Image for Scott.
5 reviews
June 30, 2009
I am reading "Mastering Regular Expressions" by Jeffrey Friedl, and am really enjoying it. Not only is it a topic that I find very interesting, but Jeffrey does a great job of leading you (and challenging you) on a path of discovering the power of regex. The narrative is sometimes a bit too self-conscious (the author never lets you forget that it's HIM doing the talking), but that can be forgiven because the book is well written and interesting.

I don't read a lot of technical, "geeky" books, so I don't have a broad base for comparison. But this is definitely the best I've read. So far, my only quibble is that he says that regex should be pronounced with a hard G, as in regular, rather than a soft G, as in regina. I haven't met a programmer yet who pronounces it this way, some of whom have been using regex for many years. We pronounce it rej'eks. Personally, I find reg'eks awkward to pronounce.
116 reviews13 followers
June 13, 2008
I read the first edition many years ago and while I don't remember the contents in detail, I get the impression that this edition has a much smoother opening than its predecessor, and is thus an easier book to read for less experienced programmers. The first few chapters teach the core techniques, with could recaps and summaries, as well as a lot of useful examples.

The second half of the book is much more advanced and focuses more on the technical aspects of regex engines, ways of maximizing efficiency in regular expressions and chapters on the implementation of regular expressions in various programming languages, including Perl, Java, and PHP.

It is really a classic work and a must for anyone who wants to learn how to think about regular expressions instead of just viewing a list of metacharacters found in a language documentation file.
Displaying 1 - 30 of 80 reviews

Can't find what you're looking for?

Get help and learn more about the design.