regex-railroad Svelte Themes

Regex Railroad

Interactive regex visualizer with railroad diagrams, step-through NFA debugger, and plain English explanations. Supports JS, Python, and PCRE flavors.

Regex Railroad

See your regex. Debug your regex. Understand your regex.

Live Demo โ†’

Regex Railroad turns regular expressions into interactive railroad diagrams, plain English explanations, and a step-through NFA debugger โ€” all in the browser, with zero server dependencies. Supports JavaScript, Python, and PCRE flavors.

Features

  • ๐Ÿš‚ Interactive railroad diagrams โ€” real-time SVG rendering from regex AST
  • ๐Ÿ” Step-through debugger โ€” watch NFA execution with backtracking visualization
  • ๐Ÿ“– Plain English explanations โ€” every regex element described clearly
  • โš ๏ธ Backtracking detection โ€” static analysis warns about catastrophic patterns
  • ๐ŸŽจ Dark/light mode โ€” beautiful themes for both preferences
  • ๐Ÿ“‹ Copy for any language โ€” escape regex for JS, Python, Java, Go, Rust, C#, PHP
  • ๐Ÿ”— Shareable URLs โ€” encode full state in the URL hash
  • ๐Ÿ“š Pattern library โ€” 22 pre-built patterns for emails, URLs, IPs, dates, and more
  • ๐ŸŒ Three regex flavors โ€” JavaScript, Python, PCRE with flavor-specific parsing
  • โšก 100% client-side โ€” no server, no tracking, works offline
  • ๐Ÿงช 4,896 unit tests โ€” battle-tested regex engine

Quick Start

git clone https://github.com/ndcorder/regex-railroad.git
cd regex-railroad
pnpm install
pnpm dev

Open http://localhost:5173 and start typing a regex.

Usage

  1. Enter a regex โ€” type or paste a pattern into the input field
  2. See the diagram โ€” the railroad diagram updates as you type
  3. Read the explanation โ€” plain English breakdown appears alongside the diagram
  4. Debug with a test string โ€” enter text and step through NFA execution
  5. Copy for your language โ€” grab the escaped version for JS, Python, Java, Go, Rust, C#, or PHP
  6. Share โ€” the URL encodes your pattern, flags, flavor, and test string

Regex Flavors

Feature JS Python PCRE
Named groups (?<name>) (?P<name>) (?<name>), (?'name'), (?P<name>)
Named backreferences \k<name> (?P=name) \k<name>, \k'name', (?P=name)
Possessive quantifiers โ€” โ€” โœ“
Atomic groups โ€” โ€” โœ“
Unicode properties โœ“ โ€” โœ“
Inline flags โ€” โœ“ โœ“

Architecture

src/lib/
โ”œโ”€โ”€ parser/      Lexer + recursive descent parser โ†’ AST
โ”œโ”€โ”€ diagram/     AST โ†’ layout โ†’ SVG rendering
โ”œโ”€โ”€ engine/      NFA simulator with step recording
โ”œโ”€โ”€ explain/     AST โ†’ plain English descriptions
โ”œโ”€โ”€ copy/        Regex escaping for 7 target languages
โ”œโ”€โ”€ library/     22 pre-built regex patterns
โ”œโ”€โ”€ sharing/     URL hash encoding/decoding
โ””โ”€โ”€ stores.svelte.ts   Reactive state (Svelte 5 runes)

Testing

pnpm test          # 4,896 unit tests (Vitest)
pnpm test:e2e      # Playwright end-to-end tests
pnpm check         # TypeScript type checking
pnpm lint          # ESLint + Prettier

Building

pnpm build         # Static site output in build/
pnpm preview       # Preview production build

The build produces a fully static site (via @sveltejs/adapter-static) that can be deployed anywhere โ€” GitHub Pages, Netlify, Vercel, or a plain file server.

Tech Stack

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

MIT

Top categories

Loading Svelte Themes