A Complete Guide for Developers Across Languages and Platforms
Introduction: Why Regular Expressions Matter
- What This Book Covers
- Languages and Engines Covered
- How to Use This Book
- A Note on Notation
Chapter 1: What Are Regular Expressions?
- The Power of Pattern Matching
- A Brief History: From Automata Theory to grep
- What Regex Can and Cannot Do
- How This Book Is Organized: Your Learning Roadmap
Chapter 2: Your First Regular Expressions
- Literal Characters and Exact Matches
- Writing Your First Pattern
- The Anatomy of a Regex Operation
- Testing Patterns Interactively
Chapter 3: Metacharacters and Escaping
- The Dot Metacharacter
- Special Characters That Need Escaping
- Escape Sequences for Common Characters
- When Escaping Behavior Differs Across Engines
Chapter 4: Character Classes and Ranges
- Defining Character Sets with Square Brackets
- Ranges and Ordering Within Classes
- Negated Character Classes
- Shorthand Character Classes
- POSIX Character Classes
Chapter 5: Quantifiers and Repetition
- The Asterisk, Plus and Question Mark
- Exact and Range Quantifiers
- Greedy Matching Explained
- Common Quantifier Mistakes
Chapter 6: Anchors and Boundaries
- Start and End of String Anchors
- Word Boundaries
- Line Anchors and Multiline Mode
- Zero-Width Assertions vs Consuming Characters
Chapter 7: Alternation and Grouping
- The Pipe Operator for Alternation
- Capturing Groups with Parentheses
- Non-Capturing Groups
- Prioritizing Alternatives
Chapter 8: Backreferences and Named Groups
- Numeric Backreferences
- Named Capture Groups
- Backreferences in Replacement Strings
- Engine Support Variations
Chapter 9: Lookahead and Lookbehind Assertions
- Positive Lookahead
- Negative Lookahead
- Positive Lookbehind
- Negative Lookbehind
- Fixed-Length vs Variable-Length Lookbehind
Chapter 10: Greedy, Lazy and Possessive Quantifiers
- Understanding Greedy Behavior Step by Step
- Lazy (Reluctant) Quantifiers
- Possessive Quantifiers and Their Performance Benefits
- Choosing the Right Quantifier Mode
Chapter 11: Atomic Groups and Advanced Assertions
- Atomic Groups and Backtracking Control
- Conditional Patterns
- Recursive and Balanced Matching
- Engine-Specific Features
Chapter 12: Unicode and International Text
- Unicode Code Points vs Bytes
- Unicode Property Escapes
- Case Insensitivity Across Languages
- Grapheme Clusters and Combining Characters
Chapter 13: Matching, Searching, Extracting, Replacing
- Full Match vs Search vs Find All
- Extracting Captured Groups
- Splitting Strings on Patterns
- Replacement with Backreferences
Chapter 14: Real-World Pattern Recipes
- Email Address Validation
- URL and URI Matching
- Date and Time Patterns
- File Paths and Filenames
- Log Line Parsing
Chapter 15: Source Code and Structured Text Processing
- Tokenizing Source Code
- Parsing Configuration Files
- Working with Markup Languages
- When to Use a Parser Instead
Chapter 16: Debugging and Testing Regex
- Interactive Testing Tools
- Writing Unit Tests for Regex
- Step-by-Step Debugging Techniques
- Common Pitfalls and How to Spot Them
Chapter 17: Performance and Security
- Understanding Backtracking Cost
- Catastrophic Backtracking Explained
- Regular Expression Denial of Service (ReDoS)
- Writing Linear-Time Patterns with RE2
Chapter 18: Maintainability, Portability and Best Practices
- Readable Regex: Comments and Formatting
- Porting Patterns Across Engines
- When Not to Use Regular Expressions
- Documentation and Team Standards
Chapter 19: Regex Engines and Flavors Compared
- NFA vs DFA vs Hybrid Engines
- Engine Feature Comparison Table
- Unicode Handling Differences
- Performance Characteristics
Chapter 20: Language-Specific API Guides
- Python (re and regex modules)
- Perl (m//, s///, qr//)
- Ruby (Regexp class)
- Go (regexp package)
- Rust (regex crate)
- C (POSIX regex.h and PCRE2)
- C++ (std::regex)
- Java (java.util.regex)
- C# (.NET System.Text.RegularExpressions)
Chapter 21: Putting It All Together
- The Regex Decision Framework
- Building Your Pattern Library
- Continuing Your Learning Journey
- Final Thoughts
Glossary of Terms
Syntax and Metacharacter Cheat Sheet
- Core Metacharacters
- Quantifiers
- Shorthand Character Classes
- Common Escape Sequences
Common Patterns Reference
- Validation Patterns
- Extraction Patterns
- Transformation Patterns
Troubleshooting Guide
- Pattern does not match expected input
- Pattern matches too much (greedy problem)
- Pattern is very slow or hangs
- Pattern works in one language but not another
- Unicode-related issues
Further Reading and Bibliography
- Books
- Papers and Technical Articles
- Official Documentation
- Standards
- Online Tools