DevTools Logo

Interactive RegEx Railroad & DFA/NFA Stepper

Examples

The classic catastrophic pattern

Input
(a+)+$   against   aaaaaaaaaaaaX
Output
ReDoS: critical — thousands of backtracks on 13 characters, step ratio ≫ 8/char

The nested quantifier lets the engine retry exponentially many partitions of the a's; the debugger makes the explosion visible and safely bounded.

Greedy vs lazy in slow motion

Input
<.+>   vs   <.+?>   against   <a><b>
Output
greedy: matches <a><b> after unwinding · lazy: matches <a> immediately

Step both and watch the greedy engine run to the end of the line and backtrack, while the lazy variant exits at the first '>'.

Simplify a verbose pattern

Input
(?:[0-9\d]{1,})-(?:[A-Za-z]){4,}
Output
\d+-[A-Za-z]{4,}

Redundant classes collapse to shorthands, {1,} becomes +, and non-capturing groups that carry no precedence are dropped — language-identical, verified against the native engine.

Lookbehind as a diagram

Input
(?<=@)\w+
Output
dashed "(?<= … )" frame wrapping the \w+ lane

Zero-width constructs get their own visual vocabulary so the diagram stays honest about what consumes input and what only peeks.

About this tool

The Interactive RegEx Railroad & DFA/NFA Stepper shows what a regular expression actually is: a machine. Type a JavaScript pattern and it is parsed into an explicit syntax tree — no black box — then rendered three ways: as a classic railroad (syntax) diagram you can export as vector SVG, as the NFA produced by Thompson's construction, and as the DFA derived from that NFA by subset construction, with ε-edges drawn dashed and accepting states ringed.

The step debugger is where intuition gets built. A faithful reimplementation of a backtracking regex engine runs your pattern against your test text and logs every instruction: characters consumed, alternatives pushed, assertions checked, and — the part browsers never show you — every unwind. Play it, pause it, scrub it, or step one instruction at a time while the input caret, live backtrack counter and engine log update together.

Because backtracking is also a security story, the tool grades every run for ReDoS risk: a static analysis flags nested quantifiers with overlapping starts like (a+)+ and ambiguous alternation like (a|a)*, while a dynamic signal measures steps executed per input character. The simulation is hard-budgeted, so a catastrophic pattern truncates with a warning instead of freezing the tab — and the simplified-pattern export (a{1,} → a+, [0-9\d] → \d, redundant groups removed) gives you the safe rewrite to copy.

Everything is computed locally: the parser, compiler, automata and VM are pure TypeScript with no RegExp delegation and no network calls, so patterns and test text never leave the page.

How to use

  1. Enter pattern and text

    Type a JavaScript regex (without delimiters), toggle the i/m/s flags, and add the text to debug against — or pick a preset like the ReDoS demo.

  2. Read the railroad diagram

    Boxes are terminals, stacked rows are alternation, the lane under a box is its quantifier loop, and dashed frames are lookaround.

  3. Compare NFA and DFA

    Switch to the NFA · DFA tab: the NFA mirrors Thompson's construction exactly; the DFA shows the subset-construction view with merged states and interval-labelled edges.

  4. Step the engine

    Open the step debugger and play, pause, scrub or single-step. The log lists pc (instruction), pos (text index) and the action; the counter accumulates backtracks live.

  5. Check ReDoS and export

    Read the risk badge and its reasons, then export the standalone SVG diagram and the optimized pattern from the export panel.

Use cases

Debugging a pattern that 'works on regex101 but not in prod'

The step log shows exactly which alternative the engine takes and where it unwinds, on the exact text that fails.

ReDoS review before shipping user-supplied patterns

Paste candidate patterns, read the risk grade and the structural reason, and replace with the simplified export.

Teaching and learning automata

(a|b)*abb is the canonical Thompson example — draw it, derive the DFA, then watch the backtracking engine disagree with both.

Documenting a gnarly pattern for teammates

Export the railroad SVG straight into a PR description or README instead of describing the regex in prose.

Common mistakes

Mistake:Reading the DFA as the execution model

Fix:Browsers run backtracking, not DFAs — the NFA/DFA views explain the language, the step debugger shows the real engine.

Mistake:Trusting a 'safe' score on short test text

Fix:ReDoS scales with input length; the static reasons (nested quantifiers, ambiguous alternation) are the ones that matter regardless of sample size.

Mistake:Expecting every flavor to render

Fix:The parser targets the JavaScript flavor's core; \p{...} property escapes are reported as unsupported rather than drawn wrong.

Frequently asked questions

References & standards

Distributed Systems & Network Topology Simulator

Build a network topology from load balancers, API gateways, microservices, message queues, distributed databases and caches, then inject chaos — kill nodes, partition the network, packet loss, latency spikes, circuit breaker trips — and watch Raft leader election, split-brain and Hystrix-style breaker state react live. Export the topology as Docker Compose, Kubernetes manifests, Mermaid or PlantUML. Entirely client-side, educational simulation.

Typography Anatomy & Variable Font Lab

Load a TTF/OTF/WOFF/WOFF2 font and inspect glyph Bézier outlines, baseline/x-height/cap-height guides, kerning pairs, OpenType features and live variable-font axis sliders — export CSS @font-face, font-variation-settings and fallback metric overrides.

Pixel Art Sprite Studio

Draw retro pixel art on an 8x8 to 64x64 grid with pencil, flood-fill, ordered-dither and symmetry tools, curated PICO-8/Game Boy/NES/C64/Endesga-32 palettes, multi-layer compositing, and a frame timeline with onion skinning. Export static PNG, animated PNG, GIF, a sprite-sheet atlas (Pixi/Phaser/Godot/Unity JSON), or a CSS steps() animation snippet.

Digital Logic Gate & Circuit Simulator

Build digital circuits from AND/OR/NOT/NAND/NOR/XOR/XNOR gates, tri-state buffers, switches, clocks and 7-segment displays; wire flip-flops, latches and multiplexers into adders and counters. Runs an event-driven propagation-delay simulation with High-Z and driver-conflict detection, packages sub-circuits into reusable ICs, and exports a truth table, K-Map minimization, Verilog, VHDL, and a documented JSON+SVG schematic. Everything runs client-side; circuits never leave the browser.

2D Fluid Dynamics & Particle Physics Sandbox

A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

GLSL Shader Art & Visual FX Playground

A live GLSL fragment-shader laboratory running on WebGL2 with the full Shadertoy uniform set (iResolution, iTime, iTimeDelta, iFrame, iMouse, iChannel0..3). Write shaders with syntax highlighting and see them recompile on every keystroke, with compiler errors mapped back to your line numbers and highlighted in the editor, plus a live FPS counter. The gallery ships raymarched spheres, tori and a Mandelbulb fractal, Voronoi and FBM procedural noise, cyberpunk grids, plasma waves, a neon audio visualizer and matrix rain. Export any shader as Three.js ShaderMaterial code, a React Three Fiber component, a standalone single-file WebGL2 HTML page or plain GLSL — or record the canvas straight to WebM video. A Canvas2D plasma fallback keeps the tool usable where WebGL2 is unavailable.