Regular Expressions CookbookFor me, Regular Expressions have always been a curse because I only use them only a few times a year. I never get enough exposure to the point where I can memorize them, let a lone master them. A cookbook on Regular Expressions is just the thing I’ve been waiting for.

Mr. Goyvaerts is recognized as a regular expression expert and maintains a blog at There are many useful tidbits there, I recommend following his blog regularly, if you want to keep up your regex chops. is yet another site authored by Mr. Goyvaerts, which also contains a wealth of information on regexes. Prior to getting this book, I had downloaded the regex tutorial in PDF format a few months back, and would assume this document may have led to the development of the cookbook.

One of the more interesting aspects of the authors’ background is that he has become quite well-versed on regexes in many different programming languages. His regex software tools offer regex support for many languages and this book also follows suit. In typical cookbook fashion, each chapter cites a problem and solution. This book goes further and shows you differences between many flavors of regular expressions. .NET, Java, JavaScript, PCRE, Perl, Python, and Ruby are the most commonly used and thus are the languages covered in the recipes in this book. Additionally, the recipes discuss variations of each problem/solution pair, and are often cross-referenced with other solutions within the book. There are even “gotchas” emblazoned with a bear trap icon describing particularly easy-to-stumble-on problem areas. What more could you ask for?

Upon receiving the book, I was pleased with the size of the book. The index ends on page 493. Browsing the table of contents reveals over 100 Regular Expression recipes which are logically and well organized into 8 chapters.

The first chapter gives a brief introduction and history into Regular Expressions, as well as references to many regular expression tools. This is a perfect way for someone who is completely new to regular expressions to get started understanding them. Having the right tool to help you construct the right regex is extremely valuable. Regex Buddy was the first program I used from Mr. Goyvaerts Company, and have referred it to colleagues and friends. It will definitely help eliminate some of the frustration of learning regular expressions. Many times I have thought that the name “Regular Expressions” is inappropriate for the strings of gibberish that so many of us labor to get right. Where did the name come from? It should be no surprise that this book also explains the ‘History of the Term Regular Expression’

Chapter Two covers “Regular Expression Skills” and is full of many recipes covering much-needed basics of regular expressions. Having looked over the titles for each recipe they are all very practical, well-explained and not contrived. You will find use for many of these recipes in your day-day programming tasks.

Chapters 4-8 are full of Regular Expressions to solve real-world problems, and the solutions span the many different regex flavors mentioned earlier.

If there were one recipe I would have preferred to see in this book, it would be a regex to find or skip C/C++ code inside of C comments. Since C comments can span multiple lines, there are probably many pitfalls here just waiting for a casual regex user like myself.

One feature I’d like to see from the publisher is that the source code be made available for download. Regular Expressions can be very complicated and it would be very easy to mistype one, thus creating other problems. Downloadable source code would help to eliminate this.

This is an example of a recipe I could have used many times in the past.

Problem #5.7, Page 300.

“Find Words Near Each Other.

You want to emulate a NEAR search using a regular expression. For readers unfamiliar with the term, some search tools that use Boolean operators such as NOT and OR also have a special operator called NEAR. Searching for “word1 NEAR word2” finds word1 and word2 in any order, as long as they occur within a certain distance of each other.

Solution (the reader should substitute word1 and word2 with their terms of interest. This solution allows up to five words to separate word1 and word2)


Regex options: Case insensitive

Regex Flavors: .NET, Java, JavaScript, PCRE, Perl, Python, Ruby”

Having my last name mispronounced since I was old enough to remember, I was curious how Mr. Goyvaerts pronounces his last name. Well, there’s even a webpage for that too,, as well as an introduction on Mr. Goyvaerts’ background. I’ve found these to be informative and recommend his blogs as supplements to his book.

Overall, I’m very satisfied with Regular Expressions Cookbook, and recommend it to everyone just learning or brushing up on their regular expression skills. Armed with this book, and some of the software tools mentioned in Chapter 1, you’ll be ready to tackle an upcoming programming assignment using a Regular Expression or two.