The black art of regular expressions

Published November 8th, 2005

I frequently come across people on coding help forums ask for assistance with a problem to which the answer, as far as I am concerned, consists of just two words: regular expressions. And I’m shocked, although not surprised, to find out how many people are either a) ignorant or b) afraid of them.

A regular expression (abbreviated as regexp, regex, or regxp, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules

Source

If you find yourself working with strings, familiarity with regular expressions is indispensable. A topical example: if your site has a form of any kind, you should be checking all data in case of cross-site scripting attacks, and regular expressions provide exactly the sort of tools you need.

I’m far from an expert when it comes to regex, but after getting past the initial “Oh my god, what is that meaningless string of symbols? Run away!” stage, and trying a few things out, I found that in fact the basics weren’t that hard to grasp. Once I had taken those on board, bit by bit I began to explore the powerful commands and now I’m using regex all over the place.

So, to the point: do yourself a favour and check out one of the many regular expressions tutorials. And get yourself a copy of Regex Coach, a handy little tool that helps you build and test regex patterns on-the fly.

Good luck!

Get a Trackback link

1 Comments

  1. Dougal Campbell on November 16, 2005

    Regexp Coach is a great tool for debugging regexps. As a matter of fact, I was helping a friend with a regular expression yesterday, and when my first attempt at a pattern didn’t work as expected, I fired up Regexp Coach to debug it. I was quickly able to figure out my mistake.

Leave a comment

Comment Policy: First time comments are moderated. Please be patient.

OpenID

Anonymous