Regexes fundamentally can't do that [1].
[0] https://github.com/Microsoft/TypeScript/issues/14833
[1] https://en.wikipedia.org/wiki/Turing_completeness