Regular Expressions
Read, write and debug regular expressions: characters and classes, anchors, quantifiers, groups, lookaround, Unicode, flavours and ReDoS safety.
36 lessons: 36 free with Pro answers.
Examples run with Node.js 24.21.0, quickjs 0.32.0, Python 3.14.8 and Pyodide 314.0.7.
Who it is for
Developers, data analysts and anyone cleaning text, across JavaScript, Python, PCRE and RE2 flavours.
What you will be able to do
- Explain how a regex engine searches text, and predict the leftmost match a pattern finds
- Write patterns with literals, escapes, classes, anchors and quantifiers, inside the string literals of real code
- Capture, name and reuse parts of a match with groups, alternation and backreferences
- Use lookaround, flags and Unicode properties correctly, and know which flavours support each
- Port a pattern between JavaScript, Python, PCRE2, RE2 and other flavours without changing what it matches
- Search, extract and clean text with regex in command-line tools, spreadsheets, SQL and code
- Validate formats with patterns that state their limits, and choose a parser where a regex falls short
- Recognise catastrophic backtracking, prevent ReDoS, and handle untrusted patterns and input safely
Revise and practise
- Practice: every exercise and quiz (32 exercises, 36 quizzes)
- Regular Expressions flashcards
Modules and lessons
What the labels mean
- Free lesson, Pro answers
- the whole lesson is free; the model answers to its interview questions open with a pass
- Pro
- opens with a Pro, Premium or Ultimate pass
Minutes are reading time.
What a pass opens in this track
72 interview answers. The same pass opens every other track and every Pro tool.
- Module 1
Foundations: what a regex is and how matching works
What a regular expression is, where patterns run in editors, code, command lines and databases, and how an engine walks the text to find the leftmost match.
- What a regular expression is and where it runs Free lesson, Pro answers: 15 minutes
- How an engine finds a match, step by step Free lesson, Pro answers: 20 minutes
- Module 2
Characters, escapes and character classes
Literal characters, metacharacters and the dot, writing patterns inside string literals, character classes with ranges and negation, and the shorthand classes.
- Literals, metacharacters and the dot Free lesson, Pro answers: 15 minutes
- Writing patterns in code: strings and escaping Free lesson, Pro answers: 25 minutes
- Character classes, ranges and negation Free lesson, Pro answers: 20 minutes
- Shorthand classes for digits, words and spaces Free lesson, Pro answers: 25 minutes
- Module 3
Anchors and boundaries
Start and end anchors, multiline mode and what counts as a line, and word boundaries for whole-word search in each flavour.
- Anchors: start, end and multiline mode Free lesson, Pro answers: 30 minutes
- Word boundaries and whole-word search Free lesson, Pro answers: 20 minutes
- Module 4
Quantifiers: greedy, lazy and possessive
Repetition with star, plus, question mark and counted braces, greedy and lazy matching, and possessive quantifiers and atomic groups that never give text back.
- Repetition with *, +, ? and {m,n} Free lesson, Pro answers: 30 minutes
- Greedy and lazy quantifiers Free lesson, Pro answers: 25 minutes
- Possessive quantifiers and atomic groups Free lesson, Pro answers: 25 minutes
- Module 5
Groups, alternation and backreferences
Capturing and non-capturing groups, named groups in every flavour, alternation and the order of its choices, and backreferences that match the same text again.
- Capturing and non-capturing groups Free lesson, Pro answers: 15 minutes
- Named groups across regex flavours Free lesson, Pro answers: 10 minutes
- Alternation and the order of choices Free lesson, Pro answers: 20 minutes
- Backreferences: matching the same text again Free lesson, Pro answers: 20 minutes
- Module 6
Lookaround and advanced constructs
Lookahead and lookbehind as conditions that consume no text, the lookbehind limits of each flavour, and the conditionals, recursion and extras of PCRE2.
- Lookahead: conditions without consuming text Free lesson, Pro answers: 20 minutes
- Lookbehind and its limits in each flavour Free lesson, Pro answers: 20 minutes
- Conditionals, recursion and PCRE2 extras Free lesson, Pro answers: 15 minutes
- Module 7
Flags, modes and Unicode
Flags and inline modifiers, free-spacing patterns with comments, Unicode code points, case and normalisation, and Unicode properties, scripts and graphemes.
- Flags and inline modifiers Free lesson, Pro answers: 20 minutes
- Readable patterns: free-spacing and comments Free lesson, Pro answers: 25 minutes
- Module 8
Flavours compared and regex in each language
How the regex flavours differ, porting a pattern safely, and the regex APIs of JavaScript, Python, PHP, Perl, Go, Java, .NET, Ruby and Rust.
- Flavours compared: porting a pattern safely Free lesson, Pro answers: 25 minutes
- JavaScript regex techniques for text jobs Free lesson, Pro answers: 25 minutes
- Python regex techniques and the regex module Free lesson, Pro answers: 25 minutes
- Regex in PCRE2, PHP and Perl Free lesson, Pro answers: 20 minutes
- Regex in Go, RE2 and re2js Free lesson, Pro answers: 25 minutes
- Regex in Java, .NET, Ruby and Rust Free lesson, Pro answers: 20 minutes
- Module 9
Regex in tools, spreadsheets, web standards and data cleaning
POSIX patterns in grep, sed and awk, regex in spreadsheets, SQL and analytics tools, patterns in HTML, JSON Schema and config files, and cleaning text data.
- grep, sed and awk: regex on the command line Free lesson, Pro answers: 25 minutes
- Regex in spreadsheets, SQL and analytics tools Free lesson, Pro answers: 20 minutes
- Regex in HTML, JSON Schema and config files Free lesson, Pro answers: 20 minutes
- Module 10
Validation patterns and their limits
Validating numbers, identifiers and dates with patterns that state what they accept, and why emails and URLs need a parser more than a regex.
- Validating formats: numbers, IDs and dates Free lesson, Pro answers: 20 minutes
- Emails, URLs and when to use a parser Free lesson, Pro answers: 30 minutes
- Module 11
Performance, ReDoS and security
Backtracking engines and automata, catastrophic backtracking and ReDoS, writing and measuring fast patterns, untrusted input, and reviewing patterns you did not write.
- Backtracking engines versus automata engines Free lesson, Pro answers: 35 minutes
- Catastrophic backtracking and ReDoS Free lesson, Pro answers: 20 minutes
- Writing fast regexes and measuring them Free lesson, Pro answers: 30 minutes
- Regex with untrusted patterns and input Free lesson, Pro answers: 20 minutes
- Reviewing regexes from forums or AI assistants Free lesson, Pro answers: 25 minutes
Related tools
Official documentation
- ECMAScript 2026 Language Specification (ECMA-262, 17th edition) (Ecma International)
- re: Regular expression operations (Python Software Foundation)
- pcre2pattern: Perl-compatible regular expressions (revised API) (PCRE2 Project)
- RE2 syntax (Google)
- Unicode Technical Standard #18: Unicode Regular Expressions (Unicode Consortium)
- POSIX.1-2024 Base Definitions, Chapter 9: Regular Expressions (The Open Group and IEEE)