tags:

views:

482

answers:

8

Hi Guys,

I want to purchase a regular expressions book centered around PHP. I found this one that looks ok: Friedl - Mastering Regular Expressions but it looks like general information about regular expressions and not PHP.

My question is: Does the syntax for regular expressions translate exactly from one language to another, ie-> PHP? or do I need a PHP regular expressions book?

cheers, Keith

+1  A: 

The syntax is not the same but you'll learn alot about regex if you read this book that's you mentionned.

It used Perl but it's so well written.

It will be easy to translate your regex to php after reading the book.

Regards.

Luc M
A: 

Its a very good book. It covers regexs in amazing detail.

But its not the easiest of reads!

Fortyrunner
I thought it was very easy to read. In fact, it's one of those rare computer books that's actually a pleasure to read. What's difficult is the concepts it teaches--it can take a while for some of them to sink in. It did for me, anyway.
Alan Moore
A: 

this is a little off topic, but here goes:

  1. I rarely buy programming books because there are usually out of date by them you get it home
  2. I've learned a lot more by hacking together examples and posting questions in various forums (now thankfully we have SO).
  3. learning a general concept, like Regular expression, rather than how they are implemented, RegEx in PHP for example, is much better way of learning a concept than the other way around.

Just my $0.02

So, to answer your question, I would RegEx in general, then try to do it in PHP. I think Perl is the best way to go.

cbrulak
You must be buying the wrong books if they go out of date by the time you get home - or you live an excessively long way away from your bookshop.
Jonathan Leffler
@jonathan leffler agreed... even my highly-specific technical books are still useful for 3-5 years, and books like Code Complete are of course timeless. For a book to be out of date within a year of purchase, it'd have to be so damn useless I wouldn't buy it in the first place.
Rex M
I agree about books. Read a javascript book from 2004 and see if its as relevant as a book from 2008. (sometimes/sometimes not) The best books I've found are either reference for the language or a book that has a general approach to programming.
Syntax
A: 

Go for that one book, this is the reference on the subject. The last edition does try to cover multiple languages incl. IIRC PHP.

Keltia
+1  A: 

My suggestion, don't but a regex book, I bought Regex Buddy and in using it learned alot of regex and it is more useful in the long term then the book will be anyway.

Unkwntech
A: 

I think the best way to get familiar with some coding stuff is to look at examples, try to understand them and practicing afterwards. Especially for regular expressions the amount of syntax rules is quite small. If you just want your regexs to do something you better look at some regex directories on the web and get them faster and more up-to-date than in a book. If you want to use regex, I think the best way is to learn it by doing. There are examples for almost every possible use case of regular expressions on the web.

okoman
+3  A: 

I feel Like I'm going to be stealing some of Scott Hansleman's thunder when saying this but,

"So you have a problem. And you've decided to use a regular expression to solve it. Now you have two problems..."

As far as syntax goes, there are some minor differences between the PHP and say Perl or .net regular expressions (mostly in how they handle escape characters). The bigger question is why you'd want a book on the regular expressions at all.

If you're looking to become proficient at writing regular expressions yourself, then a book might be helpful for getting the 'zen' of it and giving you a good lens through which to learn. It really is like learning a whole other programming language, though it becomes a very powerful tool if you do so.

If, on the other hand, you don't want to become a Regex guru and you just want to approach some specific tasks, I might recommend sites like http://www.regexlib.com, which is kind of like a wiki for good regular expressions. There are also tools like RegexBuddy that can give you a good, interactive way of fine tuning some of the expressions into giving you the results you want without really having to grasp the whole of the regular expressions themselves. These kinds of tools would probably serve you better than any book you can find if your goals are more practical.

Raumornie
The "two problems" quote is not Hanselman's - it's usually attributed to Jamie Zawinsky, but seems to have earlier roots in a quote by David Tilbrook (with AWK instead of regex as the butt of the joke). See: http://regex.info/blog/2006-09-15/247
Michael Burr
I stand corrected.I can add only that I've heard it a few dozen times from Hanselman; didn't bother researching it though. Good to know...
Raumornie
+7  A: 

Definitely buy Mastering Regular Expressions. Don't be put off by the fact that it covers other languages besides PHP. Your real goal is to learn regexes, and no other learning resource, online or dead-tree, is anywhere near as good as that book. The language-specific chapters just cover the syntax, features and peculiarities of each language's regex support. The real meat is in the rest of the book, and it's all useful, no matter what language you work in.

Also, be on the lookout for The Regular Expression Cookbook, by Goyvaerts and Levithan. It's due out May 15, and from what I know of the authors, I expect it to be very good. But get Friedl's book now; the G&L book won't replace Friedl's, but supplement it.

(Disclaimer: I'm not affiliated with the authors, publishers or retailers of those books. The affiliate codes in the Amazon links are for the authors themselves.)

Alan Moore
Our book will cover PHP in detail.
Jan Goyvaerts
Regular Expressions Cookbook is shipping now. Jeff Atwood, one of the founders of stackoverflow.com says it's "outstanding": http://www.codinghorror.com/blog/archives/001274.html
Jan Goyvaerts
My copy arrived a few days ago, and it's even better than I expected. Nice one, Jan!
Alan Moore
If anyone doesn't have a copy of Regular Expressions Cookbook yet, O'Reilly and I are doing a giveaway at regexguru.com in which anyone can participate until the end of the month (28 Feb 2010).
Jan Goyvaerts
Thanks for your answer.. I bought my new copy of Mastering Regular Expressions book today!
Bragboy