Regexdrill

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.

Start practicing free

Level 1: Basics

Literals, the dot, character classes and ranges, negated classes, quantifiers, anchors and escaping special characters.

  1. Find a literal wordFree
  2. The dot matches one characterFree
  3. Character class: gray or greyFree
  4. Ranges: a letter and two digitsFree
  5. Negated class: no vowelsFree
  6. Counted repeats: 3 to 5 digitsPro
  7. One or more: goal, gooal, goooalPro
  8. Optional letter: color or colourPro
  9. Anchors: lines that start with ERRORPro
  10. Escaping: a price like $4.99Pro

Level 2: Groups and alternation

Capture and non-capturing groups, alternation and its precedence, backreferences and optional parts.

  1. Alternation: cat, dog or birdPro
  2. Alternation with anchorsPro
  3. Capture a standalone yearPro
  4. Group without capturingPro
  5. Backreference: doubled wordsPro
  6. Matching quote marksPro
  7. Optional group: phone extensionPro
  8. Repeated group: dotted numbersPro
  9. Alternation inside a groupPro
  10. 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.

  1. US ZIP and ZIP+4Pro
  2. US phone number formatsPro
  3. Dates YYYY-MM-DDPro
  4. 24-hour times HH:MMPro
  5. 12-hour times with AM or PMPro
  6. Simple email addressesPro
  7. Hex colorsPro
  8. IPv4 addresses, 0 to 255Pro
  9. URL slugsPro
  10. SKU codesPro
  11. Currency amounts with commasPro

Level 4: Extraction and cleanup

Log lines, key=value pairs, CSV fields, hashtags, host names, trimming and collapsing whitespace, reformatting dates and names.

  1. Log lines: level and messagePro
  2. key=value pairsPro
  3. The third CSV fieldPro
  4. HashtagsPro
  5. Host names from URLsPro
  6. Trim whitespacePro
  7. Collapse repeated spacesPro
  8. Reformat MM/DD/YYYY as YYYY-MM-DDPro
  9. Swap Last, First to First LastPro
  10. Strip HTML tagsPro
  11. Keep only the digitsPro

Level 5: Advanced

Lookahead and lookbehind, lazy versus greedy, named groups, password rules, word boundaries, the u flag and the m flag.

  1. Lookahead: amounts before USDPro
  2. Negative lookahead: not starting with unPro
  3. Lookbehind: amounts after $Pro
  4. Negative lookbehind: positive numbers onlyPro
  5. Lazy vs greedy: the first quoted textPro
  6. Named groups: year, month, dayPro
  7. Password rules with lookaheadsPro
  8. Word boundaries: replace a whole wordPro
  9. Unicode letters with the u flagPro
  10. 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