tdog.blog header

Demystifying Regular Expressions

May 20th, 2004 by Tom Myer

Hi there! Welcome to our blog. Don't forget to sign up for our free RSS feed. We Triple Dog Dare Ya! And thanks for visiting!

To the unitiated, regular expressions look like gobbledegook. I have to admit that even after 10 years of playing around with them that I still find them amusing (and sometimes frustrating). What are regular expressions? Technically speaking, regular expressions allow you to define patterns to match and extract data.

For example if you wanted to match all first names in your customer list that started with the letter T, had 6 letters in them, and ended in a consonant, your regular expression (in Perl, anyway) would look like this:

m/T\w{4}[^aeiou]/;

In other words, match:

* a capital letter T
* followed by four “wordish” looking characters
* followed by any of NOT a,e,i,o, or u (i.e., a consonant)

That regular expression would match Thomas and Trevor, but not Timmy (not enough letters!). Given their extraordinary power, regular expressions are used by a wide variety of Web programming languages to complete an astounding number of daily tasks.

Tags: No Comments

Leave A Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.