Regular Expressions for Regular Programmers

If you've followed my blog for any length of time, you know that I am a total regular expression fanboy. It's almost embarrassing how much I love the damn things. I'm pretty sure my teammates roll their eyes every time they see yet another class I've touched that has using System.Text.RegularExpressions at the top. You might as well rename it to JeffHasBeenHere.

This is a companion discussion topic for the original blog entry at:
1 Like

Does it have a recipe for cake? CakePHP that is. I use RegexBuddy 3 and I have lists of useful regular expressions in my notes.

I hate them. Nothing shows more the pure snobery of geeks. Because they were able to master this intellectual perversion they feel they are superior, huh get a life.
It’s not that they don’t have their uses, but in 9 of 10 times other methods should be used.
The main problem I see in them is their lack of standardisation, when you talk about Regex, do you mean perl regex (v5, v6), sed regex, any other implementation (Microsoft, and Oracle come to mind).
I didn’t choose these implementation randomly, we have in our system (the biggest translation memory system in the world) all of them, and every time something fails, it’s almost ever these f… regexes that missed some corner cases or some subtle semantic differences between the implementations. The other problem is to find where the error was, when they fail, they do not fail in a simple way, they mangle a little bit their data and what happens after that is random. I prefer ou C apps, when they fail (which they do not anymore) they fail for real, core dump and all. But the bugs are corrected within minutes.

Sorry if I sounded rude, but there were too much agreement here, that’s not sane :wink:

i always mutter to my colleagues, “Stop me, i’m about to use another regex…”

i think regex’s benefit more than any other code from unit testing.

not that i always do that, because i often think “nah, not this time, it’s so simple!” – the crazy edge cases often come back to bite.

(plus, love the fact that now, by mousing over a commenter’s name, i can see the url of their site. Nice improvement)

three big “oh, wow, I didn’t realize that” moments

That tells a lot. I’d personally interpret that as the commonly observed fact that Regular Expressions are vastly underestimated. They are far more powerful than they seem. And that would be Powerful as in Chainsaw, not just Powerful as in Biceps.

Like anything powerful it will hurt the one who wields it uncautiously.

By the way, @DevMan: that’s actually why the name is very good. It describes the academic properties of these expressions: RE (BRE or ERE) (much like indicators like LA(LR), LL(n) are used to indicate the power of a parser).
Like so many scientific notions, the name can be deceptive, for the uninformed

I found the infallible logic of ConkCurrency irresistibly hilarious (not a good thing).

Neither is an Ad-hominem attack a good thing.

Why wouldn’t you be able to purchase an ebook in India from the site in US? You can most certainly get a PDF.

You missed the whole point - fair price as an instrument against copyright infringement, so to speak.

The fact that there are EEE’s shows that publishers hold the concept of variable pricing valid. It’s older than at least two decades.

You can also find the same material online: regular expressions in all shapes and sizes.

As if this post is only about regular expressions. It appears to be more about the book. You seem to have realised that - talking of clicks and whatever else - but not put 2 and 2 together - to realise the comment was about fair price based on lifestyle.

If your Feds screw up any further, it wont sound so hilarious. Trust me, it won’t. Check out what happened to Brazil and Japan in the late 90s.

There are countless places to learn regex for free on today’s web. Does Jeff not know that? Sure he does. I know that too. But this is a good time to get good people - authors of a book on a strictly hacker realm - to read about and take note of this bigger problem which they may not have given a priority to. And in general to increase awareness of this issue. India is one country.

The dollar is expensive in many more countries - many that do not take outsourced jobs from you, so you have no reason to perceive a threat from them.

Do you realise that if everyone outside US/UK buys these books at small prices, authors still stand to gain more money?

This is also a nice way to reciprocate the freebies they give us - in clear words, suggesting a way from which they could get that much more income and thus more encouragement to produce better works.

All this thought goes behind writing a simple suggestion. If you do not give a new idea any thought, how are you going to invent anything?

Apologies for the personal response.

Uh, what? But it’s on your recommended reading list:

The Friedl book was the best of the available options at the time (2004); I’ll switch it out ASAP.

The Friedl book was the best of the available options at the time (2004); I’ll switch it out ASAP.


1 Like

Mr. Friedl: don’t sweat too much, you’ve got a lot of fans. I am one. I admit I’m going to check out the Cookbook too, on the grounds that you can’t get too much of a good thing.

Been a reader for a while but just bought this on your recommendation, RegEx has never quite been accepted by my brain, hopefully this will finally do it!

Jeffrey Friedl introduced me to the folks at O’Reilly, and has been very supportive of my and Jan’s previous work. He was also one of the technical reviewers for Regular Expressions Cookbook, and provided a harsh critique that helped us make some improvements. I appreciate Atwood’s great comments about this book, but honestly, Friedl’s Mastering Regular Expressions is perhaps my favorite techical book–and it’s a must read for serious regexers.

@Kris, O’Reilly picks the covers. More specifically, Edie Freedman (according to

@Roger, Jeff never approached us about this post, nor vice versa. And he bought it himself (according to this post), although I’m sure O’Reilly would’ve been happy to provide a free reviewer copy (email them if you’re interested in this sort of thing).

@ConkCurrency: Contact your favorite publisher of technical books in India and ask them to buy the rights from O’Reilly to re-publish the book in India in a format and at a price suitable for the Indian market.

Also, if you’re wondering what the $&!@( that nasty looking thing on the cover of the book is:

It’s a Musk Shrew.

Not sure why the Friedl book gets the cool wise Owl while Jan and Steve get a freakin’ rat. I guess them’s the breaks…

David, you are last in life though. Congrats.

I personally think that the Musk Shrew is cute! I wish each copy came with either a plush or real Musk Shrew. I’d be willing to shell out an extra $4.99 for that!

Here is an interactive web-based regex tester.

There’s a funny post where an author of an O’Reilly book takes issue with the creature on the front. This is a link to an F# blog - Chris Smith’s completely unique view:

Also, Jeff, so you know, you’re responsible for me running out and buying Regex Buddy.

I like the Musk Shrew! :slight_smile:

“I’ve never been a fan of the classic regular expression reference book, Friedl’s Mastering Regular Expressions.”

Uh, what? But it’s on your recommended reading list:

And to follow up…
Here is what the cover ended up being