Do you understand the internals of regex matching? Regex is a very complex system, for me to explain to you why that happens accurately would require you to know a lot about regex. To put it this way, I'm currently studying the algorithm used by one regex library, and it is aboyt 70 pages of text, and that just describes the algorithm, not the entire regex system. It's not something I can just say "here is why it does that" It is a very complex process to explain.