Split out of #23, which fixed the crashes on flat patterns. This one is a compatibility gap, not a crash: deep nesting already declines cleanly.
Measured
new RegExp("(".repeat(d) + "a" + ")".repeat(d)) through zig-js test262 --eval (ReleaseFast, zig-regex@3e8654e) against node v24.4.1:
| nested groups | zig-regex (via zig-js) | node |
|---|---|---|
| 50 | runs | runs |
| 200 | runs | runs |
| 500 | runs | runs |
| 1,000 | SyntaxError: invalid regular expression | runs |
| 2,000 | SyntaxError: invalid regular expression | runs |
| 5,000 | SyntaxError: invalid regular expression | runs |
| 20,000 | SyntaxError: invalid regular expression | SyntaxError |
Non-capturing groups behave the same way with a different threshold — (?: nesting runs at 500 and is refused at 2,000 — and a nested quantifier ((?:…)* repeated) is refused from 200. Nested v-flag classes are fine: […] nested 5,000 deep runs.
No depth crashes at any size tested, so this is about where the ceiling sits, not about stack safety.
Unknown
I did not identify what produces the refusal — there is no explicit nesting or depth limit in the parser, and the message reaching JavaScript is zig-js's generic mapping of a compile failure. Worth finding which error the library actually returns before deciding the fix: a raised limit, or a limit that is explicit and documented with a message that says what was exceeded.
Done
Nesting depths that other engines accept either compile, or are refused with an error that names the limit it hit; whichever is chosen, the threshold is pinned by a test so it cannot drift silently.