[prog] Learn Code the Hard Way - RegEx

Peggy Russell prusselltechgroup at gmail.com
Mon Jan 30 21:11:37 UTC 2012


> I'm woefully deficient in my understanding of regular expressions. In order
> to start fixing this I'm going to be going through the RegEx lessons on
> learncodethehardway.com.

Regex Coach (http://weitz.de/regex-coach/) is a nice tool. In addition to 
showing the results, it will show how the regular expression was processed.

The book Mastering Regular Expressions and the site www.regular-expressions.info
are most educational. The first couple of chapters cover the basics, but
the real payload are the chapters "The Mechanics of Expression Processing" and
"Crafting a Regular Expesssion". MRE book is as "dry" as they come :-), I think
that is where regular-expression.info helps.  

I started reading the perl help file, perlretut, because I wanted to 
understand the output from: 

  perl -Mre=debug -e '"string" =~ /regex/'

I read on stackoverflow that python has something similar:

  python
  import re
  re.compile("^\[font(?:=(?P<size>[-+][0-9]{1,2}))?\](.*?)[/font]",re.DEBUG)

Sed was mentioned. If interested in Sed, Peteris Krumin at
http://www.catonmat.net/blog/sed-one-liners-explained-part-one/,
did an excellent job explaining the one-liners (he did one on Perl and
Awk too). Although the material is above and beyond regular expressions, 
his approach of examining many examples in detail and writing about it, 
is very helpful.

Peggy Russell





More information about the Programming mailing list