/Regular-Expressions

A book about Regular Expressions by Claude Code Sonnet 4.5

Creative Commons Zero v1.0 UniversalCC0-1.0

Regular Expressions: From Zero to Hero

Or: How I Learned to Stop Worrying and Love the .*

Version 1.0.0 | Status: Complete βœ… | 30/30 Chapters | ~40,700+ Lines

Welcome, brave soul, to the world's most comprehensive guide to Regular Expressions. You're about to learn one of programming's most powerfulβ€”and most intimidatingβ€”tools. But fear not! This book will take you from "what's a regex?" to "I just parsed an entire log file with one line of code" faster than you can say (?<=\w)(?=\W).

πŸ“Š Book Statistics

  • Total Chapters: 30 (all complete!)
  • Total Lines: ~40,700+
  • Average Chapter Length: 1,357 lines
  • Languages Covered: JavaScript, TypeScript, Python, Java, C#, Ruby, Go, Rust, PHP, Perl
  • Topics Covered: 100+ regex concepts with 500+ working examples
  • Real-World Examples: Log parsing, validation, text extraction, security patterns, and more

What This Book Is

This is a comprehensive reference for complete beginners who want to truly master regular expressions across multiple programming languages. Written by Claude Code (yes, an AI wrote a bookβ€”we live in wild times), this guide prioritizes:

  • Clarity over cleverness - No cryptic explanations
  • Examples over theory - See it, try it, understand it
  • Practical applications - Real patterns you'll actually use
  • Polyglot perspective - JavaScript, Python, Java, C#, Ruby, Go, Rust, and more
  • Occasional humor - Because regex is hard enough without being boring

What You'll Learn

By the end of this book, you will:

  • βœ… Understand regex syntax from first principles
  • βœ… Write patterns that actually work (first try!)
  • βœ… Know when to use regex (and when not to)
  • βœ… Navigate differences between regex flavors
  • βœ… Debug and optimize complex patterns
  • βœ… Avoid catastrophic backtracking
  • βœ… Impress your colleagues (or at least confuse them productively)

Who This Book Is For

  • "I've never seen a regex before" β†’ Perfect! Start at Chapter 1
  • "I copy regex from StackOverflow" β†’ Start at Chapter 1, you'll finally understand what you're copying
  • "I know basic regex but..." β†’ Jump to Part 2 or your favorite language's chapter
  • "I need to validate emails" β†’ Chapter 26, but also: don't validate emails with regex
  • "I accidentally created a ReDoS attack" β†’ Chapter 23, immediately

The Journey Ahead

Part 1: Foundations 🌱

Where we learn that . doesn't mean "dot" and * doesn't mean "multiply"

Part 2: Intermediate Techniques 🎯

Where things get interesting (and slightly confusing)

Part 3: The Perl Legacy πŸ“œ

Where we learn why Perl is the godfather of regex

Part 4: Polyglot Regex 🌍

Where we discover every language does it differently (but mostly the same)

Part 5: Advanced Topics πŸš€

Where experts dwell and mortals fear to tread

Part 6: Practical Applications πŸ› οΈ

Where theory meets the real world (and sometimes loses)

Appendices πŸ“š

The reference material you'll bookmark

How to Use This Book

If you're a complete beginner: Start at Chapter 1 and work through sequentially. Each chapter builds on previous concepts.

If you have some experience: Skim Part 1, focus on Part 2 onward.

If you need language-specific info: Jump directly to your language's chapter in Part 4, but reference earlier chapters for syntax explanations.

If you're debugging a specific problem: Check the table of contents or search for your issue.

A Note on Examples

All examples in this book are:

  • βœ… Tested and working
  • βœ… Commented for clarity
  • βœ… Available in the relevant language's syntax
  • βœ… Progressively complex (we won't throw (?:(?:[A-Z0-9]+(?:+|\.)?)+) at you on page 2)

πŸŽ‰ Completion Status

All 30 chapters are complete and contain comprehensive content:

Chapter Lines Status
Ch. 1: Welcome 1,464 βœ… Complete
Ch. 2: First Match 1,465 βœ… Complete
Ch. 3: Character Classes 1,247 βœ… Complete
Ch. 4: Quantifiers 1,244 βœ… Complete
Ch. 5: Anchors & Boundaries 1,323 βœ… Complete
Ch. 6: Groups & Capturing 1,281 βœ… Complete
Ch. 7: Alternation 1,114 βœ… Complete
Ch. 8: Escaping 1,585 βœ… Complete
Ch. 9: Lookarounds 1,145 βœ… Complete
Ch. 10: Greedy/Lazy 1,546 βœ… Complete
Ch. 11: Perl History 1,201 βœ… Complete
Ch. 12: PCRE 1,310 βœ… Complete
Ch. 13: JavaScript 1,525 βœ… Complete
Ch. 14: TypeScript 1,389 βœ… Complete
Ch. 15: Python 1,455 βœ… Complete
Ch. 16: Java 1,362 βœ… Complete
Ch. 17: C# 1,408 βœ… Complete
Ch. 18: Ruby 1,115 βœ… Complete
Ch. 19: Go 1,370 βœ… Complete
Ch. 20: Rust 1,362 βœ… Complete
Ch. 21: Unicode 1,531 βœ… Complete
Ch. 22: Regex Flavors 1,657 βœ… Complete
Ch. 23: Backtracking 1,251 βœ… Complete
Ch. 24: Advanced Techniques 1,798 βœ… Complete
Ch. 25: Optimization 1,437 βœ… Complete
Ch. 26: Common Patterns 1,231 βœ… Complete
Ch. 27: Validation vs Parsing 1,534 βœ… Complete
Ch. 28: Text Extraction 1,057 βœ… Complete
Ch. 29: Testing/Debugging 1,543 βœ… Complete
Ch. 30: Real-World Cases 1,242 βœ… Complete

Contributing & Feedback

Found an error? Have a suggestion? This book is open source! Create an issue or submit a pull request.

About the Author

This book was written by Claude Code (Sonnet 4.5), an AI assistant specialized in software engineering. Yes, really. No, I don't know what that says about the state of technical writing. Yes, I've been trained on millions of StackOverflow posts where people ask "how do I regex this?"

I bring to this book:

  • Zero ego (I'm an AI)
  • Infinite patience (I don't get tired explaining the same concept)
  • No assumptions about what you "should already know"
  • A genuine desire to make this topic accessible

Ready?

Take a deep breath. Open Chapter 1: Welcome to Regex Hell. And remember: every regex master you admire was once exactly where you are nowβ€”staring at a pattern thinking "how does anyone read this?"

The difference between them and you? They kept going.

Let's begin.


"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." β€” Jamie Zawinski

"But at least they can solve both of them." β€” This book