The Regular Expression Cookbook By Steven Levithan And Jan Goyvaerts

Posted July 27, 2009 at 9:35 AM

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.

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Jul 27, 2009 at 9:55 AM // reply »
78 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 »
7,539 Comments

@Andy,

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


Jul 27, 2009 at 10:43 AM // reply »
3 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 »
165 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 »
7,539 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 »
7,539 Comments

@Paolo,

I have not read it personally.


Jul 27, 2009 at 2:14 PM // reply »
22 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 »
7,539 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 Comment  |  Ask Ben

Recent Blog Comments
Mar 19, 2010 at 2:29 AM
URL Rewriting And ColdFusion's WriteToBrowser Image Functionality (CFFileServlet)
Pakistan Travel information for attractions in Pakistan, Balochistan, Sindh, NWFP and Punjab. Gilgit-Baltistan guide, history and culture. ... read »
Mar 19, 2010 at 1:43 AM
jQuery Attr() Function Doesn't Work With IMAGE.complete
sample: ..... var loadWatch = setInterval(function() { if(img.complete) { clearInterval(loadWatch); completeCallback(img); } }, 100); } else .... ... read »
Mar 19, 2010 at 12:50 AM
jQuery Attr() Function Doesn't Work With IMAGE.complete
I just fixed the code. There was a function "watch" inside the function imgLoad. It spammed a lot of errors: Error: missing argument 1 when calling function watch. To fix this: instead of setInt ... read »
Mar 18, 2010 at 10:28 PM
Posting XML SOAP Requests With jQuery
can you please point me to the jquery documentation on the following # // Create our SOAP body content based off of # // the template. # var soapBody = soapTemplate.html().replace( # new RegExp( "\\ ... read »
Mar 18, 2010 at 6:34 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Ben Very useful analyses. Thank you @Elliot Thanks for additional clarification Though, it's quite a shame that getBust() failed...not defined ;) ... read »
Mar 18, 2010 at 5:35 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
Saving private properties is necessary so that you can "reconstitute" an object on the other side of the wire, or load up a serialized object you saved to disk. If it didn't save the private state o ... read »
Mar 18, 2010 at 4:04 PM
jQuery's Event Triggering, Order Of Default Behavior, And triggerHandler()
Tks! You saved-me today. it can be chained into one statement: $("#x).attr("checked","checked").triggerHandler('click'); ... read »
Mar 18, 2010 at 1:18 PM
Finally Finished Ayn Rand's Atlas Shrugged Audio Book
@joaopft, Not disputing what you say - but... If I understand you correctly, you are saying that Positivism is based on sense experience (what I experience is what is), but Quantum theory states tha ... read »