guh.me - gustavo's personal blog

Book review – Introducing Regular Expressions

Regular expressions are scary, especially if don’t understand them. When I started programming, I thought of them as black magic, and that they were evil and complicated (unsavvy kid, uhm?). As I got more skilled, I perceived that they would help me solve problems fast (and sometimes would double the problems ;), I knew it was time to read a book on it. I chose Introducing Regular Expressions, by Michael Fitzgerald, because it was very short and it goes straight to the point - perfect for beginners who like fast paced books. I’ve greatly improved my witchcraft regex skills, and now people even seek advice from me, lol. Next I’m reading Mastering Regular Expressions, which is pretty hardcore.

Book on Amazon: http://www.amazon.com/gp/product/1449392687

My Personal Notes

Chapter 1: What’s a regular expression?

Capturing groups and back references

(\d)\d\1          707-827-7019

Quantifiers

Numbers in curly braces tell the number of occurrences that you want to look for.

\d{3}-?\d{3}-?\d{4}

\d{3,4} : minimum and maximum quantity to match.

Expression analysis: (\d{3,4}[.-]?)+

Quoting literals

Final expression (that matches an american phone)

^(\(\d{3}\)|^\d{3}[.-]?)\d{3}[.-]?\d{4}

Chapter 2: Simple pattern matching

Regex test tools

Pattern matching

Chapter 3: Boundaries

Chapter 4: Alternation, groups and back references

Chapter 5: Matching Unicode and other characters

Chapter 6: Quantifiers

Chapter 7: Lookarounds

Chapter 8: Marking up a document with HTML