Feeds

Mastering Regular Expressions

Not just a text book – a real guide

  • alert
  • submit to reddit

Build a business case: developing custom apps

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!

Boost IT visibility and business value

More from The Register

next story
The Return of BSOD: Does ANYONE trust Microsoft patches?
Sysadmins, you're either fighting fires or seen as incompetents now
Microsoft refuses to nip 'Windows 9' unzip lip slip
Look at the shiny Windows 8.1, why can't you people talk about 8.1, sobs an exec somewhere
Intel's Raspberry Pi rival Galileo can now run Windows
Behold the Internet of Things. Wintel Things
Linux Foundation says many Linux admins and engineers are certifiable
Floats exam program to help IT employers lock up talent
Microsoft cries UNINSTALL in the wake of Blue Screens of Death™
Cache crash causes contained choloric calamity
Eat up Martha! Microsoft slings handwriting recog into OneNote on Android
Freehand input on non-Windows kit for the first time
Linux kernel devs made to finger their dongles before contributing code
Two-factor auth enabled for Kernel.org repositories
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.
7 Elements of Radically Simple OS Migration
Avoid the typical headaches of OS migration during your next project by learning about 7 elements of radically simple OS migration.
BYOD's dark side: Data protection
An endpoint data protection solution that adds value to the user and the organization so it can protect itself from data loss as well as leverage corporate 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?