> The question is about finding opening tags in XHTML using a regular expression<p>Bzzzt, wrong, sorry! The question is about finding open tags in the presence of XHTML self-closing tags. That difference alone places these interpretations gulfs apart. But there’s more: it does not specify that the input document is even XHTML, <i>only</i> that XHTML-style self-closing elements may be present. In fact the original question was barely
minutes old and tagged merely “regex” when that famous answer was written in 2009; the question was not tagged with “xhtml” until 2012, and not by the original author either.<p>Revealingly, then, if we review the broader context (i.e question history) of the original question author, it’s clear that yes indeed <i>they were trying to fix a malformed document</i>, and in particular to normalise it <i>into</i> XHTML, with focus on fixing up any so-called “dangling tags”. For this task, the suggestion of “use a parser” is indeed sound advice.<p>The real moral here is, don’t be a jerk about the precise semantics of a question, look at what the person <i>needs</i>, and help them ask better questions.<p>Otherwise, you’re just gonna discover that there’s always a bigger jerk, and they’re on Stack Overflow, moderating your stuff.