I'm working on a regex pattern to match nested parentheses with exponential depth. While I have a working solution for shallow nesting, it fails when the nesting depth becomes very deep.
Here's my current regex pattern:
const regex = /\(([^()]+)\)/;
const text = "(((A))) (((((B))))) (((((((C)))))))";
const matches = text.match(regex);
console.log(matches);
In this example, I want to match the innermost content within the deepest set of parentheses, like "C". However, my current regex code only matches "A" and "B."
I'm looking for a regex pattern that can handle matching the innermost content within deeply nested parentheses like the "C" in the example. Any insights or corrections to my regex code would be greatly appreciated!