Regex Golf
A puzzle game where you write the shortest regex to match target strings — beat the par score across 10 levels!
Regex Golf — Master Regular Expressions Through an Addictive 10-Level Puzzle Game Where You Write the Shortest Possible Pattern
- Each level presents two lists: strings that your regex must match (shown in green) and strings it must not match (shown in red). Read the level description carefully — it often contains subtle clues about pattern requirements. Regex Golf is modeled after the classic code golf concept, where the challenge is achieving correct functionality with the fewest possible characters. Your job is to craft a single regular expression that perfectly discriminates between the two sets — matching all 'match these' strings while rejecting all 'don't match these' strings.
- Type your regular expression into the input field. As you type, the tool instantly evaluates your pattern against every string in both lists — green highlights mark correctly matched strings, red highlights flag incorrect results (either false positives that should not match or false negatives that should). This real-time feedback loop is designed to help you learn regex syntax through experimentation — you can see immediately whether your anchors (^ and $), character classes ([aeiou]), quantifiers (*+?{'{'}{'}'}), groups ((...)), and lookarounds ((?=...)) are behaving as expected.
- Compare your solution's length against the par score displayed for each level — par represents the character count of an optimal or near-optimal solution. Scoring works like golf: fewer characters than par earns a Birdie 🐦, equal to par is Par, and more characters is a Bogey. Don't worry if your first solution is longer — the real learning happens when you refine and shorten your regex after seeing it work. Complete all 10 levels to win, and feel free to revisit earlier levels to improve your score. Your progress is saved in browser local storage so you can continue anytime.
Enable JavaScript to use these tools.