How to Match Nested Parentheses and Balanced Tags with Balancing Groups in .NET Regex
Balancing groups (?<name>) and (?<-name>) turn a .NET regex capture group into a stack, so one pattern can match arbitrarily nested parentheses or <div> tags. The full pattern, how the stack works, inner-content capture with (?<inner-open>), and the gotchas verified on .NET 11 RC1: the empty-stack check, catastrophic backtracking, NonBacktracking, and mixed bracket types.