Regex Golf
Craft the shortest valid regular expression to match all positive test strings while excluding all negative test strings. Minimize character count to beat par scores across 8 progressive tiers.
Level 1: Image File Extensions
Write a pattern that matches valid image files ending in .png, .jpg, .jpeg, or .webp, while rejecting documents, executables, and media files.
Must Match (0/6)
Must NOT Match (6/6)
What is Regex Golf?
Regex Golf is a specialized programming puzzle where the objective is to write the shortest possible regular expression that satisfies a binary partition: matching every string in a target list (the positives) while strictly rejecting every string in a forbidden list (the negatives).
In standard code golf, points are scored by minimizing total source bytes. In Regex Golf, your stroke score is the literal character length of your regex pattern. The shorter the pattern, the higher your optimization rating.
Core Regex Minimization Strategies
Avoid verbose ranges like [0-9] when \d saves 3 characters. Similarly, use \w instead of [a-zA-Z0-9_] and leverage case-insensitive flags (/i) to collapse dual-casing classes.
In strict production validation, full string anchors (^...$) are mandatory. In golf, if the positive set contains an exclusive character or substring absent from all negative examples, a partial substring match without anchors saves 2+ characters immediately.
Capture groups combined with numbered backreferences (\1, \2) allow matching mirrored structures, repeated words, and mathematical properties like composite vs. prime string counts with minimal code.
Zero-width assertions ((?=...), (?!...)) verify conditions without consuming characters. Negative lookaheads allow excluding specific forbidden sub-patterns in a single pass.
Regex Golf vs. Production Regular Expressions
- Explicit start and end anchors (
^and$) to prevent partial substring injections. - Clear named capture groups (
(?<domain>...)) for maintainability. - Defensive bounds to avoid catastrophic backtracking (ReDoS vulnerabilities).
- Exploits corpus asymmetries (identifying characters unique to positives).
- Replaces verbose logical OR branches with overlapping character classes.
- Focuses on motor memory, syntax precision, and deep understanding of regex engine mechanics.
Frequently Asked Questions
Which regex dialect does this game use?
Dev Arcade Regex Golf evaluates patterns using the native JavaScript (ECMAScript) RegExp engine directly in your browser. It supports all standard JavaScript metacharacters, unicode properties, character classes, capture groups, backreferences, and lookarounds.
Why does my regex match locally but fail the level?
To pass a level, your expression must satisfy two simultaneous conditions: it must match 100% of the positive test strings AND match 0% of the negative strings. If your pattern accidentally matches even one negative string, the level will remain uncompleted.