logoalt Hacker News

tiagodtoday at 5:22 PM2 repliesview on HN

I think even for single opening tags like asked there are impossible edge cases.

For example, this is perfectly valid XHTML:

    <a href="/" title="<a /> />"></a>

Replies

chungytoday at 7:52 PM

No, that is not valid. The "<" and ">" characters in string values must always be escaped with &lt; and &gt;. The correct form would be:

    <a href="/" title="&lt;a /&gt; /&gt;"></a>
comextoday at 6:02 PM

If you already know where the start of the opening tag is, then I think a regex is capable of finding the end of that same opening tag, even in cases like yours. In that sense, it’s possible to use a regex to parse a single tag. What’s not possible is finding opening tags within a larger fragment of HTML.

show 1 reply