Developer skills
Regular expressions for beginners: a practical guide
The parts of a regular expression you will use every week, each with a small example, plus the mistakes that catch everyone out.
4 min read
Write a regular expression that matches every string on one list and none on the other. 24 puzzles, from anchors to lookarounds.
Match every string that contains "cat".
Loading the puzzle…
catconcatenatebobcatdogcartactPatterns are JavaScript regular expressions with no flags. A string counts as matched if the pattern is found anywhere in it, so use ^ and $ to pin it to the start and end.
Regular expressions are one of the most useful tools a programmer has, and one of the hardest to learn from a reference page. Regex Runner teaches them the way they are really used: you have some strings you want and some you do not, and you need a pattern that tells them apart.
There are 24 puzzles in three packs. Each shows a list of strings your pattern should match and a list it should not. As you type, every string is marked right or wrong, so you see straight away what each part of your pattern does.
| Type a pattern | Type in the pattern box |
|---|---|
| Next puzzle, once solved | Enter |
| Jump to a puzzle | Tab to its number and press Enter |
| Sound on or off | M (outside the pattern box) |
| Type a pattern | Tap the pattern box |
|---|---|
| Next puzzle | Tap Next puzzle |
| Jump to a puzzle | Tap its number |
Patterns are JavaScript regular expressions with no flags, so matching is case-sensitive. A string counts as matched if the pattern is found anywhere in it, the way RegExp.test works. To match a whole string, pin the pattern with ^ at the start and $ at the end.
Each pack has 8 puzzles. Beginner covers literal text, anchors, character classes and counts like {3}. Intermediate adds groups, alternation with |, word boundaries and backreferences. Advanced uses lookaheads, lookbehinds and patterns that check whole formats, like dates and IP addresses.
You can play the puzzles in any order. Every puzzle has many right answers; the one shown by Show an answer is only one of them.
For each puzzle the length of your shortest solving pattern is saved in this browser, and the puzzle number turns green. If you show the answer first, solving that puzzle is not recorded on this visit. Try coming back to a solved puzzle to find a shorter pattern.
Some patterns, such as (a+)+$, can take an extremely long time on certain strings because the regex engine tries every way of splitting the text. This is called catastrophic backtracking. Regex Runner stops any pattern that runs for longer than a moment and tells you, so the page never freezes.
Developer skills
The parts of a regular expression you will use every week, each with a small example, plus the mistakes that catch everyone out.
4 min read
Developer skills
Off-by-one loops, NaN and NULL, falsy zero, shared defaults, sorting surprises and forgotten awaits: what goes wrong and the habit that catches each one.
4 min read
Developer skills
What a branch actually is, what HEAD points to, and what merge, rebase, cherry-pick and reset do to the commit graph.
4 min read
Developer
Spot the buggy line in short JavaScript, Python and SQL snippets. 8 a round, with the cause and the fix after each.
Developer
A typing test for programmers: type real JavaScript, Python, Rust and SQL code against the clock.
Developer
Flip bits to build each number in binary. How many can you make in 60 seconds?