Feeds

Mastering Regular Expressions

Not just a text book – a real guide

  • alert
  • submit to reddit

5 things you didn’t know about cloud backup

Book review Like SQL and XML, regular expressions are an essential tool in every developers’ toolbox. Processing text, which is pretty much what most programs do when you think about it, is so central a concern that even without regular expressions most developers quickly build up a library of functions and idioms for text matching, replacement, parsing, token extraction etc.

Regular expressions go a whole lot further and are, in effect, a specialised language for text processing in all its messy glory. The downside to this extra power is that it comes at a price – regular expressions have a reputation for being difficult to craft, difficult to debug and difficult to read. No wonder that regular expressions are often seen as the preserve of obscurantist hackers who make a virtue of impossible-to-decipher Perl one-liners.

Jeffrey Friedl’s Mastering Regular Expressions, now into a thirdedition, is something of a classic of its kind. The aim is simple enough – to make regular expressions your friend. No matter what your platform or programming language of choice, Friedl’s book is designed not just to get you started, but to set you well on the way to expertise.

The key to achieving this mastery is to provide plenty of examples throughout the entire 500+ pages of text. From the word go the emphasis is on real examples, building each one up in complexity to match the kind of problems that occur with real text rather than the sanitised kind that only seems to exist in text books. Want to strip out IP addresses or URLs? What might appear to be a straightforward case ends up being tricky and complicated – but along the way Freidl points out the kinds of problems that will bite you if you’re not careful. He also repeatedly makes the point that there’s a trade-off between completeness, performance and the state of the data you’re dealing with.

The first six chapters are devoted to general topics – providing plenty of extended examples, discussion of different flavours of regular expression engines, some history, coverage of efficiency issues and so on. These six chapters include material on regular expression support in Perl, Java, Python, Ruby, C# and VB.NET, PHP as well as tools like egrep, awk and so on.

The final four chapters of the book are devoted to regular expression support in specific languages and platforms: Perl, Java, .NET and PHP. In each case there is a combination of more worked examples and detailed discussion based on the material covered in the first six chapters. For developers using any of these languages this material is a bonus that consolidates the core understanding that Friedl establishes in the earlier sections of the book.

As well as the clear writing style, the book also scores well in terms of overall design. The typography stands out in terms of clarity when displaying regular expressions and the text that it matches – it’s always clear what’s what, with the different components clearly marked out. Another good design feature is that the questions Friedl poses the reader always have a solution on the next page – you don’t ever see the answer before you’ve had a chance to ponder the question, and neither do you have to flick to the end of the book. It makes answering the questions a more natural part of the reading process.

Mastering Regular Expressions

Verdict: Highly recommended to anyone wanting to really get to grips with regular expressions.

Author: Jeffrey Friedl

Publisher: O’Reilly & Associates

ISBN:0596528124

Media: Book

List Price: £31.99

Buy this book at Register Books at Reg Developer's special discounted price!

Secure remote control for conventional and virtual desktops

More from The Register

next story
BBC: We're going to slip CODING into kids' TV
Pureed-carrot-in-ice cream C++ surprise
China: You, Microsoft. Office-Windows 'compatibility'. You have 20 days to explain
Told to cough up more details as antitrust probe goes deeper
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
Windows 7 settles as Windows XP use finally starts to slip … a bit
And at the back of the field, Windows 8.1 is sprinting away from Windows 8
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Endpoint data privacy in the cloud is easier than you think
Innovations in encryption and storage resolve issues of data privacy and key requirements for companies to look for in a solution.
Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?