Regular expressions¶
Regular expressions are a tiny language for describing patterns in text. Once you can read them, a whole class of "find this", "extract that", "validate this" jobs become one-liners instead of nests of string slicing. They're notoriously cryptic at first sight, so this guide builds them up slowly and then puts them to work.
Start here¶
If re is new to you, work through the Learn section in order — four short notebooks, around fifteen minutes each. Every code cell can be edited and run in place, directly on the page; no install required.
If you already know the basics and are looking for a specific technique, jump to the Recipes section, or scan the Reference for syntax and the re module's API.
What this guide covers¶
Learn — your first pattern, character classes and quantifiers, groups and capturing, find-and-replace.
Recipes — extracting data from messy text, validating email addresses, using regex with file I/O, and the mistakes most people make.
Reference — re module API, regex syntax, and the flag list.
Concepts — how the regex engine actually works, and when reaching for regex is the right call.