Regex Marble Run turns your regular expression into a 3D marble run
Regex Marble Run is a free web page that builds your regular expression as a 3D machine.
Regex Marble Run is a free web page that builds your regular expression as a 3D machine. You type a pattern and a test string, and each letter becomes a marble that rides to the gate that tests it. A miss falls into Reject, and a match rolls to the cup. The person who posted it to Hacker News, where it drew 85 points, said a coworker who used to teach non-technical people to code built it because students always found regex hard.
Every part of the pattern gets its own piece of hardware. A brass arch reads one character, a diverter chooses a branch for the pipe symbol, greedy loops try another round first while lazy loops try the exit first, and a lookahead sends a small marble down a side track to report back. You can press Play or step through one test at a time.
The site says it lets you watch catastrophic backtracking happen, and every developer should see that once. Stack Overflow’s postmortem says a post with roughly 20,000 consecutive characters of whitespace hit a backtracking regex and caused a 34-minute outage on July 20, 2016. Cloudflare went down for 27 minutes on July 2, 2019, after a single WAF rule with a poorly written regular expression exhausted its CPUs, and at one point it had lost 80% of its traffic.
RE2, Go and Rust use linear-time engines that never revisit a position, so the same pattern that floods this machine runs in time proportional to the string length there.
If you write regex for anything that takes user input, I’d paste in your scariest pattern with a long test string and watch the marbles pile up. One of its built-in examples is a long run of spaces between two characters, which is close to what bit Stack Overflow. The poster disclosed it was built with Agent Duel, a coding-agent tool their company makes.
Watch the marbles before your users do.