Skip to content
Aback Games

Regex Runner

Write a regular expression that matches every string on one list and none on the other. 24 puzzles, from anchors to lookarounds.

  • Developer game
  • Free
  • No sign-up
  • Keyboard
  • Touch
Pack
Puzzle1/8
Solved0/24
Shortest–

Find the cat

Match every string that contains "cat".

Loading the puzzle…

Should match

  • cat
  • concatenate
  • bobcat

Should not match

  • dog
  • cart
  • act

Patterns 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.

Enjoying Regex Runner? Share it:Post on X (opens in a new tab)

About Regex Runner

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.

How to play Regex Runner

Regex Runner controls

Keyboard
Type a patternType in the pattern box
Next puzzle, once solvedEnter
Jump to a puzzleTab to its number and press Enter
Sound on or offM (outside the pattern box)
Touch screens
Type a patternTap the pattern box
Next puzzleTap Next puzzle
Jump to a puzzleTap its number

Regex Runner rules

What counts as a match

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.

Packs and puzzles

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.

Records

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.

Slow patterns

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.

Tips and strategy

  • Start with the strings that should not match. They show you what your pattern must avoid, which is usually the hard part.
  • Use ^ and $ whenever a puzzle is about a whole string. Without them, a pattern that matches part of a bad string still counts as a match.
  • Square brackets match one character from a set: [aeiou] is one vowel, [^aeiou] is one character that is not a vowel, and [0-9a-f] is one hex digit.
  • A dot matches any character, so escape it as \. when you mean a real full stop.
  • Counts apply to the thing just before them: \d{3} is three digits, (ab){2} is abab, and colou?r makes only the u optional.
  • A lookahead like (?=.*\d) checks that something is there without using up any of the string, so you can stack several checks at the start of a pattern.

Frequently asked questions

Which regex flavour does Regex Runner use?
JavaScript, as built into your browser, with no flags. Most of what you learn carries over to Python, Java, PHP and other languages; the main differences are in advanced features like lookbehind support and named groups.
What is the best way to practise regular expressions?
Work on small, concrete problems where you can see the result immediately. That is what these puzzles are: each one is a real task, like matching dates or file names, with instant feedback on every string.
Why does my pattern match a string I did not expect?
Usually because the pattern is found somewhere inside it. "cat" matches "concatenate". Add ^ and $, or \b for a word boundary, to say where the match must start and end.
Is a shorter regex better?
Not always in real code, where clarity matters more. Here the shortest pattern is a fun extra challenge, and finding it usually teaches you something about how the engine works.

Guides and tips

Common coding bugs and how to spot them

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

Bug Hunt

Spot the buggy line in short JavaScript, Python and SQL snippets. 8 a round, with the cause and the fix after each.

  • Keyboard
  • Touch

Code Typer

A typing test for programmers: type real JavaScript, Python, Rust and SQL code against the clock.

  • Keyboard
  • Touch

Bit Flip

Flip bits to build each number in binary. How many can you make in 60 seconds?

  • Keyboard
  • Touch

All games