All 52 regex exercises
Regexdrill is regular expression practice in your browser. Every exercise gives you an exact rule and a handful of lines that should and should not match. You type a pattern, matches highlight live on every line, and Check runs it against hidden strings too, so a pattern that only fits the examples fails. The exercises are listed here level by level. 5 are free without an account; Pro unlocks the rest.
Level 1: Basics
Literals, the dot, character classes and ranges, negated classes, quantifiers, anchors and escaping special characters.
- Find a literal wordFree
- The dot matches one characterFree
- Character class: gray or greyFree
- Ranges: a letter and two digitsFree
- Negated class: no vowelsFree
- Counted repeats: 3 to 5 digitsPro
- One or more: goal, gooal, goooalPro
- Optional letter: color or colourPro
- Anchors: lines that start with ERRORPro
- Escaping: a price like $4.99Pro
Level 2: Groups and alternation
Capture and non-capturing groups, alternation and its precedence, backreferences and optional parts.
- Alternation: cat, dog or birdPro
- Alternation with anchorsPro
- Capture a standalone yearPro
- Group without capturingPro
- Backreference: doubled wordsPro
- Matching quote marksPro
- Optional group: phone extensionPro
- Repeated group: dotted numbersPro
- Alternation inside a groupPro
- Grouped alternatives: Mr, Mrs, Ms, DrPro
Level 3: Real-world validation
US ZIP and ZIP+4, phone formats, dates with valid months and days, times, simple emails, hex colors, IPv4, slugs, SKUs and currency.
Level 4: Extraction and cleanup
Log lines, key=value pairs, CSV fields, hashtags, host names, trimming and collapsing whitespace, reformatting dates and names.
Level 5: Advanced
Lookahead and lookbehind, lazy versus greedy, named groups, password rules, word boundaries, the u flag and the m flag.
- Lookahead: amounts before USDPro
- Negative lookahead: not starting with unPro
- Lookbehind: amounts after $Pro
- Negative lookbehind: positive numbers onlyPro
- Lazy vs greedy: the first quoted textPro
- Named groups: year, month, dayPro
- Password rules with lookaheadsPro
- Word boundaries: replace a whole wordPro
- Unicode letters with the u flagPro
- Multiline flag: TODO linesPro
Try the first five exercises free.
No sign-up needed for the first five. If it works for you, Pro unlocks all 52, and a free account saves your progress and your patterns across devices.
Start practicing free