Skip to content
Back to the catalog
Project regex-engineLanguagesAdvancedBeta

Build your own regex engine

Build a regex engine from scratch. Turn expressions into automata with backtracking, groups and character classes without using a regex library.

Build it in your language

The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.

Guide language

The stage guides read in this language. Only languages this project is fully translated into show up here; the interface language does not change.

What this project is about

Regular expressions look like an esoteric language until you build the engine that runs them. Then they become what they are: a small tree and a machine that walks it.

You'll parse the expression, turn it into an automaton and run it against text. You'll implement groups, quantifiers and character classes, and see first-hand why certain expressions take forever.

Roadmap

8 stages across 4 phases. Every stage comes with its guide and its tests: you move on when they pass.

  1. Phase 12 stages

    Basic matching

    Literals, the dot, anchors, and a first minimal recursive engine.

    1. 01Literals and dot
    2. 02Anchors and search
  2. Phase 23 stages

    The full syntax

    A parser for quantifiers, alternation, character classes and groups.

    1. 01Quantifiers
    2. 02Alternation
    3. 03Classes and groups
  3. Phase 32 stages

    Backtracking with captures

    Captured groups, lazy quantifiers and substitution.

    1. 01Captures
    2. 02Lazy quantifiers and replacement
  4. Phase 41 stage

    Without blowing up

    NFA simulation and a performance comparison against the backtracking engine.

    1. 01NFA simulation

Before you start

Your own regex engine: a parser for the syntax (concatenation, alternation, quantifiers, classes, anchors, groups), automaton construction, backtracking execution with group capture, and a second NFA-simulation implementation that doesn't blow up on pathological input.

  • json-parser
    Coming soon

    Build your own JSON parser

    Build a JSON parser from scratch. Tokenize input, parse the grammar, construct a syntax tree and report useful errors for invalid JSON.

    Beginner7 stages~6 hLanguages
    tokenizerparsingrecursion

    TypeScript · Python · Go · Java

  • lisp-interpreter
    Coming soon

    Build your own Lisp interpreter

    Build a Lisp interpreter from scratch. Write a tokenizer, parser and evaluator, then add closures to discover how a language executes your code.

    Advanced11 stages~16 hLanguages
    parsingASTclosures+1

    Python · JavaScript · TypeScript

  • mini-compiler
    Coming soon

    Build your own compiler

    Build a compiler from scratch. Turn source code into bytecode with lexing, an AST, semantic analysis, code generation and a virtual machine.

    Expert16 stages~30 hLanguages
    lexerASTbytecode+1

    Rust · C++ · TypeScript