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 »
10,640 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 »
168 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 »
10,640 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 »
10,640 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 »
10,640 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
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »