
Regex Golf Challenge
Write the shortest regex that matches every string in the green list and none in the red list. Scored by character count.
Last reviewed: April 2026New to this tool? Click here for instructions
Must Match
Must NOT Match
Your Best Scores (Local)
| # | Challenge | Score (chars) | Time |
|---|
How to Use Regex Golf Challenge
Regex Golf Challenge is a free online tool designed to help you improve your regex skills through a fun and engaging puzzle format. The tool presents you with a list of strings that should match and a list of strings that should not match. Your goal is to write the shortest possible regular expression that correctly discriminates between these two lists.
To use the tool, simply select a challenge from the numbered buttons above. Study the 'Must Match' (green) and 'Must NOT Match' (red) lists. Type your regex pattern in the input field. The tool will test your pattern in real-time as you type, providing visual feedback in the form of green checkmarks for matches and red X marks for non-matches. Once your regex is correct, the challenge is solved, and your character count is recorded.
When to Use Regex Golf Challenge
Regex Golf Challenge is ideal for anyone looking to improve their regex skills. Whether you're a beginner learning the basics of regular expressions or an experienced developer looking to refine your craft, this tool offers a practical and engaging way to practice and hone your skills.
The tool is particularly useful for developers working on text processing, log parsing, input validation, and other tasks where regular expressions are a key component. By challenging yourself to write the shortest possible regex, you can learn to think more creatively about pattern representations and optimize your code for performance.
How It Works
Regex Golf Challenge works by presenting you with a set of challenges, each consisting of a 'Must Match' list and a 'Must NOT Match' list. Your task is to write the shortest possible regular expression that correctly matches all strings in the 'Must Match' list and fails to match all strings in the 'Must NOT Match' list.
The tool provides real-time feedback as you type your regex, helping you to identify and correct errors as you go. Once your regex is correct, the challenge is solved, and your character count is recorded. You can also track your progress and compare your scores with your local leaderboard.
Tips, Edge Cases, and Limitations
Here are some tips and strategies to help you improve your regex skills while using Regex Golf Challenge:
1. Start with the simplest distinction: Look for a character, word, or pattern that appears in all strings in the 'Must Match' list but in none of the 'Must NOT Match' list. That single differentiator might be your entire regex.
2. Use alternation for multiple patterns: The pipe character | lets you match either of two patterns. For many challenges, a well-crafted alternation is shorter than a character class.
3. Anchors are your friends: ^ anchors to the start and $ to the end. Using ^foo is much more specific than just foo and helps avoid false matches in the 'Must NOT Match' list.
4. Character classes over alternation for single characters: [aeiou] is shorter than a|e|i|o|u when matching individual characters.
5. Negated classes like [^aeiou] can be even more powerful.
6. Quantifiers: + (one or more), * (zero or more), ? (zero or one), and {n,m} (specific counts) can replace repeated characters.
7. Lookaheads for complex constraints: Lookaheads (?=...) and negative lookaheads (?!...) let you assert a condition without consuming characters.