Regexdrill

Write regex that works on the data you have not seen yet.

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.

  • Character classes, ranges, quantifiers and anchors
  • Groups, alternation and backreferences
  • Validating ZIPs, phones, dates, emails and IPs
  • Extracting fields from logs, CSV and URLs
  • Cleanup: whitespace, date formats, HTML tags
  • Lookahead, lookbehind, lazy quantifiers, named groups

52 exercises5 levels5 free, no sign-up

Illustration of lines of text with some segments highlighted, as a pattern scans them

Type it, see it, prove it.

  1. 01
    Read the taskA short, exact rule and a handful of lines that should and should not match.
  2. 02
    Write the patternMatches highlight on every line as you type, with a pass or fail mark beside each one.
  3. 03
    Pass the hidden testsCheck runs on lines you have not seen. Feedback names the line and the kind of mistake. Hints and a reference answer follow.

Five levels, from [a-z] to lookbehinds.

10BasicsLiterals, the dot, character classes and ranges, negated classes, quantifiers, anchors and escaping special characters.
10Groups and alternationCapture and non-capturing groups, alternation and its precedence, backreferences and optional parts.
11Real-world validationUS ZIP and ZIP+4, phone formats, dates with valid months and days, times, simple emails, hex colors, IPv4, slugs, SKUs and currency.
11Extraction and cleanupLog lines, key=value pairs, CSV fields, hashtags, host names, trimming and collapsing whitespace, reformatting dates and names.
10AdvancedLookahead and lookbehind, lazy versus greedy, named groups, password rules, word boundaries, the u flag and the m flag.

Regex practice that tests the pattern, not the examples

Most regex tutorials show you a pattern next to the three strings it matches, and you nod along. Then a real log file arrives with a line nobody showed you, and the pattern either misses it or matches too much. Regexdrill was built around one rule: the only way through an exercise is a pattern that also passes the test strings you cannot see.

Each exercise is checked against the lines you see and against extra lines you do not. A pattern that simply lists the visible examples fails on the hidden ones, and you are told so. From the second failed try, one failing input is shown. That is the difference between recognizing a regex and being able to write one that holds up on Monday's data.

A regex tester that teaches, right in your browser

The pattern box works like a regex tester: as you type, every test line lights up where it matches, with a pass or fail mark beside it, so you see the effect of each character the moment you add it. The flavor is JavaScript, as built into every browser and Node.js, and for everything taught here it behaves the same as PCRE and Python's re module, apart from small syntax details such as how named groups are written.

There is nothing to install and no account needed to start. Progress and your last patterns are saved in your browser, and a free account keeps them across devices.

Regex exercises built in five levels

The 52 exercises are organized into levels, and each level only adds one or two ideas on top of what you already know.

  • Basics: a literal word, the dot, gray or grey with a class, a letter and two digits, no vowels, three to five digits, one or more, color or colour, lines that start with ERROR, escaping a price like $4.99.
  • Groups and alternation: cat, dog or bird, alternation with anchors, capturing a standalone year, non-capturing groups, doubled words with a backreference, matching quote marks, an optional phone extension, dotted numbers, Mr, Mrs, Ms and Dr.
  • Real-world validation: US ZIP and ZIP+4, phone formats, YYYY-MM-DD dates, 24-hour and 12-hour times, simple emails, hex colors, IPv4 addresses from 0 to 255, URL slugs, SKU codes, currency with commas.
  • Extraction and cleanup: level and message from log lines, key=value pairs, the third CSV field, hashtags, host names from URLs, trimming and collapsing whitespace, MM/DD/YYYY to YYYY-MM-DD, Last, First to First Last, stripping HTML tags, keeping only digits.
  • Advanced: amounts before USD with lookahead, not starting with un, amounts after a dollar sign with lookbehind, positive numbers only, lazy versus greedy on quoted text, named groups for dates, password rules, word boundaries, unicode letters with the u flag, TODO lines with the m flag.

Within a level the exercises get harder one notch at a time. By the end of Real-world validation you have written an IPv4 pattern that rejects 256 and a date pattern that rejects month 13, not because you read about it, but because the hidden tests would not pass until you did.

Open the exercise list

Learn regex by getting it wrong first

A hint is one click away, but the reference answer opens only after your second attempt. That is on purpose. Typing a pattern, watching a line fail to light up, reading the hint and fixing the quantifier yourself is the part that sticks. Copying a solution before you have tried does not.

Every exercise also explains why the reference pattern is built the way it is: why the dot needs escaping in a price, why alternation inside a group changes what the anchors apply to, why a lazy quantifier stops at the first closing quote.

Regular expression practice for the jobs regex actually does

Two levels are devoted to the work regex is used for every day, with inputs that look like the real thing.

  • Validation: form fields and import files, where the pattern has to accept every valid format and reject the rest, including the near misses.
  • Extraction: pulling a level and message out of a log line, a value out of a key=value pair, the host out of a URL, the third field out of a CSV line.
  • Cleanup: trimming and collapsing whitespace in a spreadsheet export, swapping a date format, turning Last, First into First Last, stripping HTML tags from scraped text.

Lookahead, lookbehind and the parts people avoid

Most people stop learning regex at groups and alternation and work around everything else with code. The Advanced level covers the pieces that remove those workarounds: lookahead for an amount followed by USD, lookbehind for an amount after a dollar sign, negative versions of both, lazy quantifiers for the first quoted string rather than the longest, named groups so the year and month come out labeled, word boundaries so a replacement does not hit the middle of a word, and the u and m flags.

Each one has hidden tests designed around the mistake people make without it, so you see why the feature exists before you learn its syntax.

Regex for interviews and technical screens

Regex questions come up in developer, data engineering and QA interviews, usually as a small practical task: validate this input, extract this field, clean this string. They are not hard once you have written a few dozen patterns against hidden tests. They are hard the first time, with someone watching.

Timed mode puts a clock on each exercise with hints and reference answers locked until time is up. Run through the first four levels the week before an interview and the question will feel like one more drill.

Try a timed exercise

Why hands-on beats a cheat sheet

You can keep a regex cheat sheet open and still spend twenty minutes on a pattern, because the cheat sheet tells you what each token does, not which tokens you need. The gap between recognizing and producing is the whole problem, and the only thing that closes it is reps.

A Regexdrill session is five to fifteen minutes of writing patterns, each one slightly different from the last. Ten sessions in, the character classes, the quantifiers and the group syntax are automatic, and the cheat sheet stays closed.

Regex exercises for beginners and for people who grep every day

If you have never written a pattern, Basics starts with a literal word and does not assume anything. If you already use regex in your editor, your scripts or your spreadsheets, skip to Extraction and cleanup or Advanced and look for the gaps: most people have one feature they have always worked around, usually lookbehind or lazy quantifiers, and the hidden tests find it quickly.

Every exercise is independent, so you can jump to the one you need for today's problem and come back to the rest later.

Timed mode for real fluency.Each exercise gets a clock. Hints and answers stay locked until time is up, and your best times are kept.

JavaScript next.Our sister site Scriptdrill drills everyday JavaScript functions against hidden tests, from arrays and strings to async. Try Scriptdrill

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

Start free. Pay once it clicks.

Free

$0
  • The first 5 exercises
  • Live highlighting and hidden tests
  • Timed mode
Start free

Pro

All 52
  • Groups, validation, extraction, cleanup and lookarounds
  • Reference answers with explanations
  • Progress, last patterns and best times saved to your account

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Questions

Which regex flavor is this?

JavaScript, as built into every browser and Node.js. For everything taught here it behaves the same as PCRE (PHP, grep -P) and Python's re module, apart from small syntax details such as how named groups are written.

What are hidden test strings?

Each exercise is checked against the lines you see and against extra lines you do not see. A pattern that only lists the visible examples fails on the hidden ones, and you are told so. From the second failed try, one failing input is shown.

Who is this for?

Developers, data analysts and anyone who cleans text: validating form fields, pulling values out of logs, fixing spacing and dates in a spreadsheet export, or searching code.

Is there a free version?

The first five exercises are free without an account. Pro unlocks the other 47 for $12 a month or $59 once.

Do I need an account?

No. The free exercises work without one and save progress in your browser. A free account saves progress across devices, and Pro unlocks the rest.

How do I cancel the monthly plan?

Open Account and choose Cancel subscription. You keep Pro until the end of the period you paid for and are not charged again. If Pro is not for you, you get a full refund within 14 days of paying.

What if my answer is right but marked wrong?

Patterns are checked on what they match, not on how they are written, so any correct pattern passes. If a check still gets it wrong, use the report link under the result. Reports are reviewed, and a check that is wrong gets fixed.