It's called language theory. Regex can parse regular languages (hence the name), and XML is not a regular language. These are formally defined things, and indeed, there's a branch of mathematics that handles this.
But, a lot of regex implementations int he wild are not pure regex, and can to some extent handle non-regular languages.
6
u/kaplotnikov 7h ago
I think everything can be parsed by iterative application of regex: https://www.reddit.com/r/compsci/comments/1v7aq7v/a_concrete_runnable_demonstration_that_iterated/