The Regular Expression Cookbook By Steven Levithan And Jan Goyvaerts

Posted July 27, 2009 at 9:35 AM by Ben Nadel

Tags: ColdFusion, Javascript / DHTML, Books

A few weeks ago, I was super excited to learn that regex ninja Steven Levithan coauthored the new O'Reilly book, Regular Expression Cookbook with Jan Goyvaerts. If the name Steve Levithan sounds familiar it's because Steve is a long time participant on this blog, often swooping in to demonstrate his crazy regular expression skills, pointing out issues, offering efficiencies, and leaving very detailed explanations of how regular expressions actually work; from catastrophic backtracking to "unrolling the loop," Steve has cemented himself as the go-to guy for regular expression goodness.


 
 
 

 
The Regular Expression Cookbook By Steven Levithan And Jan Goyvaerts, Released By O'Reilly Books.  
 
 
 

Over the weekend, I was able to carve out time to read the Regular Expression Cookbook and I can tell you that it is an awesome book. Not only does it contain a huge number of "recipes" for using regular expressions to solve real world problems, it has a thorough and easy-to-follow tutorial on what regular expressions are and how they work. Even if you are someone who feels very comfortable with regular expressions, I would highly recommend reading the tutorial - you will definitely learn things that you didn't know before. I certainly found myself dog-earing some new tip every few pages.

Now, not only are there some great examples in this book, the examples are executed and explained in eight different programming languages. Of course, you don't need to read them all if they are not relevant; but, I found the Java and the JavaScript explanations quite enlightening as I deal with these languages every day. For example, did you know that using the exec() command could cause infinite loops in FireFox? Did you know that you could reset the pattern Matcher object in Java if you wanted to reuse it with another subject? Do you know what the String::replaceAll() method is actually doing behind the scenes?

After the first few hours of reading, I'm sure there is only so much that my brain could retain. Of course, that's the beauty of the "Cookbook" - when you need to look something up, you have it at your finger tips. But, even if there are things that I can't remember today, just seeing the way Steve uses regular expressions to solve problems is quite inspiring. His use of lookarounds to validate inputs was brilliant. His explanations of atomic grouping and possessive qualifiers finally made it make sense to me. Even beyond the everyday problems that he solves, his examples and explanations gave me a better handle on regular expressions as a whole.

Who is this book meant for? Anyone that wants to learn more about regular expressions and how they can make your life easier. For those just getting into regex, it's easy enough to follow; and for those that have years of experience, it's thorough enough to teach you a number of tricks. I highly recommend this book for anyone who wants to get into regular expressions for the first time or for anyone who wants to take their existing regular expression skills to the next level.




Reader Comments

Jul 27, 2009 at 9:55 AM // reply »
92 Comments

Awesome Ben! I LOVE regular expressions. They make even basic text editing quicker, and more painless. I use them to quickly parse through large amounts of text, code, or the like.

One of my personal favorites:

[ \t]+$

I hate having tabs or spaces on blank lines, or at the end of lines. This little gem removes any number of spaces/tabs at the end of a line.


Jul 27, 2009 at 9:58 AM // reply »
11,241 Comments

@Andy,

Yeah, they are definitely awesome! They just make solving so many problems much easier.


Jul 27, 2009 at 10:43 AM // reply »
6 Comments

I have a copy of this book and, not that anyone here needs another recommendation after Ben's, but it's fantastic!

I have long sucked at Regular Expressions and avoided them at all costs. But being able to use this book as a reference to see how so many RegExp practices and 'tricks' are done has made me better and more comfortable using them in my apps. The authors did an awesome job.


Jul 27, 2009 at 1:15 PM // reply »
172 Comments

Thanks, Ben (and Craig)! I've got to give props to coauthor Jan Goyvaerts though, who wrote a lot of the sections that you referenced.


Jul 27, 2009 at 1:18 PM // reply »
11,241 Comments

@Steven,

Well, a great book, to be sure.


Jul 27, 2009 at 1:27 PM // reply »
34 Comments

Have you read Jeffrey Friedl's Mastering Regular Expressions?? If so, is it better than that? Because from what I've read and heard, that book is the daddy of all books when it comes to Regular Expressions.


Jul 27, 2009 at 1:28 PM // reply »
11,241 Comments

@Paolo,

I have not read it personally.


Jul 27, 2009 at 2:14 PM // reply »
29 Comments

Thanks for the recommendation. Deffo gonna give it a shot! I'm in love with regular expressions since 2005 when I stumbled on the co-author's regular expressions info site and subsequently built a code (c++) highlighting integration for phpbb.


Aug 1, 2009 at 12:19 AM // reply »
1 Comments

I found learning regular expressions pretty tough. I usually find the resources I need online, but with differences in the regex engine between languages, I had a hard time finding a good tutorial. One thing I did find that makes regex so much easier is the application Expresso. It is free and it makes writing and learning regex a breeze. Some features: translates your regex into understandable english. you can run (partial)matches with your regex against data you give. also has an expression builder where instead of you writing the expression, you can tell the application what you want the exp to do piece by piece and it will create the expression for you. Mostly I use the program to make sure I have the expression right without having to make testing pages just to see if my regex works. The program is located at http://www.ultrapico.com/. Great article I will definitely check out the book!


Aug 2, 2009 at 5:07 PM // reply »
11,241 Comments

@Samuel,

I use an app called "The RegEx Coach". I am pretty sure Steven uses one called RegEx Buddy, which, from the book's description, looks like a very beasty application.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 22, 2013 at 4:43 AM
How Do You Use The ColdFusion CFParam Tag?
'<cfparam>' or 'isDefined()and <cfset>' performs the same task.Is there any difference? ... read »
May 21, 2013 at 7:46 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
No luck. At least I have uncovered the cause, URLScan 3.1. Here is what I see in the IIS log when a file is over 30mb. 2013-05-21 23:29:05 10.105.45.128 GET /plupload/assets/jquery/jquery-1.8. ... read »
May 21, 2013 at 6:12 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
Ben, I did not see you after Pete Freitag's Lockdown session at cfObjective but he said that IIS sets file size limits at 30MB by default which just happened to be the threshold for file size when ... read »
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools