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.