RegexWars

How it works

The loop

You get a task and a set of test strings. You write one regular expression. Every test re-runs as you type, so you can see exactly which strings you are passing and where your pattern is landing.

When everything is green, you submit. That runs your pattern against a set of hidden tests you have not seen — the ones that decide whether you found the rule or just fitted the examples. Pass those and the challenge is yours.

Scoring: shorter is better

Your score is simply how many characters you typed — the pattern, plus the flags, plus the replacement string where there is one. Lower wins.

Every challenge has a par: the length of the author’s own solution. Passing is the easy half. Getting under par is the game, and it earns a bonus on top of the points for solving.

Flags count towards your score because they genuinely are a saving. i costs one character: solving Case Blind is error plus the flag, six characters in total. Spell the same thing out as [Ee][Rr][Rr][Oo][Rr] and it is twenty. If a score ignored flags it would quietly teach the wrong habit.

The four modes

  • match

    Your pattern must match every accepted string and reject every rejected one.

    Partial matches count — if a challenge needs the whole string, the reject cases will force you to anchor it.

  • capture

    The capture groups of the first match must equal the expected values, in order.

    Group 1 is the first pair of brackets. A group that did not participate counts as null.

  • extract

    Every match in the string, in order, must equal the expected list.

    Needs the g flag. Without it you only ever get the first match.

  • replace

    You supply a pattern and a replacement, and the rewritten string must match exactly.

    $1 and $2 in the replacement stand for your capture groups.

Tiers and ranks

Difficulty runs from tier 8 (a warm-up) to tier 1 (an evening, and your answer will look like a bad phone line by the end of it). The tiers rank how hard a challenge is, nothing more — what a challenge teaches is on its tags, where you can filter by it.

Tier 1 · Sorcerer55 pts
Tier 2 · Archmage34 pts
Tier 3 · Warlock21 pts
Tier 4 · Enchanter13 pts
Tier 5 · Conjurer8 pts
Tier 6 · Adept5 pts
Tier 7 · Apprentice3 pts
Tier 8 · Novice2 pts

Points accumulate into a rank, using the same names: NoviceApprenticeAdeptConjurerEnchanterWarlockArchmageSorcerer. Points are banked once per challenge, so replaying cannot farm them.

Why there is no JavaScript here

Every other challenge site lets you write code. This one does not, on purpose. A site that runs arbitrary code is a worse Codewars; a site that runs only regex is the only place to actually practise the one skill every codebase needs and nobody teaches.

It also means everything runs in your browser in a fraction of a millisecond, with no container to spin up and no cost per run — which is why every challenge here is free and always will be.

A very short primer

If any of the above was unfamiliar, this is the whole language in eleven lines.

\d
any digit. \w is any word character, \s any whitespace
[abc]
any one of a, b or c. [^abc] is anything but those
a+
one or more a. a* is zero or more, a? is zero or one
a{2,4}
between two and four a
^ $
the start and the end of the string — positions, not characters
\b
a word boundary, between a word character and a non-word one
(ab)
a group — captured, and referable later as \1
(?:ab)
a group that does not capture. Cheaper to think about
a|b
a or b. Fence it with brackets or it splits the whole pattern
(?=a)
a lookahead: assert what follows without consuming it
(?<=a)
a lookbehind: assert what came before

→ Start on any of the 68 challenges