From @dakami, a good reminder for not trying to parse (X)HTML with regular expressions. You have to read the whole thing because this excerpt doesn’t even give feel for the original.
You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.