v1.0 — JS / NO-DEPS
~13 KB
JavaScript Library Demo

Recursive
Regex

A regex engine with (?R) recursion — equivalent to Python's regex module. Plus an extended replacement syntax: #( … #) marks a recursive group, and %1 in the replacement is processed recursively.

Try:
Input
Pattern · Replace · String
Output
Ready
Translated regex (with (?R))

Pattern syntax

#(X#) wraps a recursive capture group. The engine compiles this to ((?:(?R)|X-atom)+?), allowing balanced nested matches.

Replacement

%1, %2, … reference the captures. Each substitution is itself processed by the same rule, so nested matches are unwrapped from the inside out.

Examples in this demo

Both the user-given examples ① and ② work. Note: (%1) with literal parens preserves them; use %1 alone to drop them.