Hunter basics
The two building blocks of every pattern: literal text and the wildcard dot — and how a pattern matches anywhere inside a string.
Read the rules: Literal characters in the Guide →Drill it: Pattern drills →
What you'll learn
Steps · 9
- 01Welcome, hunterBriefing
- 02Literal charactersExample
- 03Your first huntHunt
- 04Matches anywhereHunt
- 05The dot: any characterHunt
- 06Wildcards everywhereHunt
- 07More than one dotHunt
- 08Graduation huntHunt
- 09Basics completeBriefing
Regex basics: literals and the dot
A regular expression, or regex, is a short pattern that describes text. You hand it a string and it answers one question: is there a match somewhere in here? In Regex Hunter that answer decides your hunt. The pattern has to catch every target word and spare every innocent one. Regex is built into JavaScript, Python, search tools and most code editors, so what you learn here works well beyond the game.
Most patterns start with literal characters. A letter or digit in a regex stands for itself, so ink looks for an i, then an n, then a k, in that order. It doesn't care where they sit. Without extra markers a regex matches anywhere inside the string, which is why ink also finds pinky and inkwell.
The second building block is the dot. A . fills one slot with any single character: a letter, a digit, a space or a symbol. t.p fits tip, top and t-p, but never tp, because the dot always takes exactly one character. Chain a few dots to describe a fixed-length gap. These two ideas, literal text and the wildcard, are the base for every pattern you will write later.
Examples
Catches
- sing
- ringer
- kingdom
Spares
- sign
- grin
A literal matches its letters in order, at the start, middle or end of a word.
Catches
- bag
- bug
- debug
Spares
- bang
- gab
The dot stands in for exactly one character between b and g, so
bang, with two in between, is spared.Catches
- road
- bread
- rinds
Spares
- red
- rapid
- dark
Two dots mean exactly two characters, so the r and d must sit three places apart.
Catches
- 3.5
- v3.5.1
Spares
- 305
- 35
A backslash turns the dot back into a plain full stop.
Common mistakes
- Forgetting that a pattern matches anywhere.
artalso catchesstartandparty, so check the longer words you meant to spare. - Treating `.
as a full stop. It matches any character, so1.5also fits125and1x5; write\.` when you mean a real dot. - Expecting case not to matter.
applemissesApplebecause regex is case-sensitive by default; add theiflag to ignore case.
Read the rules: Literal characters in the Guide →Drill it: Pattern drills →