本页面有中文版。
Cette page est disponible en français.
Esta página está disponible en español.
Announcements

Welcome to Regex Hunter — and the joy of regex golf

Match every monster, spare every innocent, and do it in as few characters as you can. Here's what the game is, why it's worth your time, and a first trick to shave your score.

Regex Hunter logo

· 2 min read

/cat|car|can/

match

  • cat
  • carpet

spare

  • cow
  • dog

01The shortest path wins

Every day, Regex Hunter hands you two lists of words. One list is the monsters — words your pattern must catch. The other is the innocents — words it must let walk free. Write a single regular expression that matches all the monsters, none of the innocents, and you've cleared the hunt.

The twist: every character costs you. A pattern that works isn't the goal — the shortest pattern that works is. That's regex golf, and like the game it's named after, the lowest score takes the trophy.

02A two-character lesson

Say the hunt looks like this:

  • Catch: cat, car, can
  • Spare: dog, bus

The obvious answer is to spell out every monster:

Pattern11 chars · 3 fragments
/cat|car|can/

Tap a fragment to find it

Try it in the Playground

Eleven characters, and it works. But look closer — every monster starts with ca, and neither innocent contains those two letters anywhere. A regex doesn't have to match a whole word; it only has to find its pattern somewhere inside. So this is enough:

Pattern2 chars
/ca/
Try it in the Playground

Two characters. Same result. That leap — from "spell out the answer" to "find the smallest thing the monsters share and the innocents lack" — is the whole game in miniature.

03Why play?

Regex shows up everywhere: search-and-replace, log filtering, form validation, that one config file nobody fully understands. Most people learn just enough to get by and never get comfortable. Golf flips the usual pressure. Instead of "make it work," you start asking "what's actually going on here?" — and that question is how the syntax finally clicks. Character classes, anchors, alternation, quantifiers: you reach for them because they save keystrokes, and they stick because you earned them.

It's also just fun. There's a specific satisfaction in watching a clumsy 20-character pattern collapse into a tidy six.

04Three habits to start with

  • Look for shared substrings first. Before writing alternation, ask what the monsters have in common that the innocents don't.
  • Don't over-anchor. ^ and $ cost characters and are often unnecessary. Add them only when an innocent forces your hand.
  • Lean on character classes. [aeiou] beats a|e|i|o|u, and \d beats [0-9].

05See you on the board

A fresh hunt drops every day, and there's a whole archive plus practice packs if you want to warm up first. Pick today's puzzle, find the monsters' weakness, and see how low you can score.

Happy hunting.