Hello!

I just published a new version of my Understanding Python re(gex)? ebook.

This book will help you learn Python Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises. The standard library re as well as the third-party regex module are covered in this book.


Release offers🔗

To celebrate the new release, you can download the PDF/EPUB versions of Understanding Python re(gex)? for FREE till 31-Jan-2025.

Here are some more amazing offers:

info See also my blog post on how to customize pandoc for generating beautiful PDF/EPUB versions from GitHub style markdown.


What's new?🔗

  • Python version updated to 3.13
    • deprecated features, SyntaxWarning, name change from re.error to re.PatternError
  • Corrected typos, updated descriptions, timing results and external links
  • Exercises are now numbered instead of using alphabets

Videos🔗

Check out my programming tips covering Python, command line tools and Vim:


re(gex)? playground🔗

To make it easier to experiment, I wrote on an interactive app. See PyRegexPlayground repo for installation instructions and usage guide. A sample screenshot is shown below:

Sample screenshot from the Playground screen


re(gex)? exercises🔗

I wrote another TUI app to help you solve exercises from this book interactively. See PyRegexExercises repo for installation steps and app_guide.md for instructions on using this app. Here's a sample screenshot:

Sample screenshot for Python regex exercises

See my blog post Python regex cheatsheet for a quick reference.


Table of Contents🔗

  1. Preface
  2. Why is it needed?
  3. re introduction
  4. Anchors
  5. Alternation and Grouping
  6. Escaping metacharacters
  7. Dot metacharacter and Quantifiers
  8. Interlude: Tools for debugging and visualization
  9. Working with matched portions
  10. Character class
  11. Groupings and backreferences
  12. Interlude: Common tasks
  13. Lookarounds
  14. Flags
  15. Unicode
  16. regex module
  17. Gotchas
  18. Further Reading

Web version🔗

You can read the book online here: https://learnbyexample.github.io/py_regular_expressions/


GitHub repo🔗

Visit https://github.com/learnbyexample/py_regular_expressions for markdown source, example files, exercise solutions, sample chapters and other details related to the book.


Newsletter🔗

Subscribe to learnbyexample weekly — free newsletter covering programming resources, updates on what I am creating, tools, free ebooks and more, delivered every Friday.


Feedback and Errata🔗

I would highly appreciate it if you'd let me know how you felt about this book. It could be anything from a simple thank you, rating/review, pointing out a typo, mistakes in code snippets, which aspects of the book worked for you (or didn't!) and so on. Reader feedback is essential and especially so for self-published authors.

You can reach me via:

Happy learning :)