Regular Expressions for Regular Folk

This is an experimental “book” about regular expressions. It is largely visual and example-based, as opposed to most regex resources I found while I was learning. I also attempted to choose test cases that highlight some common gotchas. I think it’ll be worth your time.

Screenshot from /chapters/escapes

This book’s intended audience is regex beginners. Some programming experience is assumed. It does not go into advanced regex concepts like engine backtracking and recursive regexes—at least not at the moment.

This is also an open source project, and contributions are welcome.

Contents

  1. Introduction
  2. Basics
  3. Character Classes
  4. Character Escapes
  5. Escapes
  6. Groups
  7. Repetition
  8. Alternation
  9. Flags
  10. Anchors
  11. Lookaround
  12. Advanced Examples
  13. Next Steps

Feedback

“Learned more in just the first few pages than I have in my many years of copy-pasting regex from StackOverflow. Cheers” —digitalmaster
“Incredible resource - I liked the structured approach as opposed to guess and check regex which is what most tools offer” —scottfits
“This looks like a great resource! Like others, I vastly prefer an example-based style, and the examples are really well chosen and very illustrative.” —twicetwice
“I like the example based approach. I learn from examples far quicker than I learn from ‘explanations’. If I attempt to learn from an example and my brain hits an exception, only then do I start reading the supporting text. […]” —LeonB
Read the full discussion at Hacker News.

Translations

Translations are welcome, as long as they adhere to the license.

You can choose to publish your translation separately, but we welcome translations on here too!

Printing

A single-page version of the book is available. Print it ordinarily. Make sure to enable “Print Background Colors” on Firefox and “Background graphics” (under “More settings”) on Chrome.