Feeds

Mastering Regular Expressions

Not just a text book – a real guide

  • alert
  • submit to reddit

Securing Web Applications Made Simple and Scalable

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!

Bridging the IT gap between rising business demands and ageing tools

More from The Register

next story
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
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.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.