Use of a style or span tag, among others, is legit... and a complication for which you'll want to allow unless you can be absolutely positive from now till the heat death of the universe, that no such element will appear in the hmtl you're parsing.
I strongly disagree with the sentiment. By all means, if you're paying for your own time, feel free to make the effort to write extremely defensive code, that will last forever.

Often though, it makes less sense. See, every minute you spend coding for something that may happen between now and the end of the universe, is a wasted minute if said thing never happens, or it doesn't happen until the program is obsoleted. A minute you could have spend writing something that actual scratches a current itch, solves a problem that needs fixing now, or something that will make money right now.

In this case, I don't think we'll be generating or parsing HTML 4.01 a few decades from now; 75% will be "tag soup, but at least it works on IE 6", 20.9% will work on the designers setup, and only on the designers setup, 4% will not work anywhere, nor does it follow any known standard, and the remaining 0.1% has made an attempt to follow a newer standard.

That having said, it may (or may not) make sense for the OP to cater for such an element appearing in the HTML text. But without knowing more about the context, I can't say for sure.


In reply to Re^2: How do I select text between two bits of text? by JavaFan
in thread How do I select text between two bits of text? by sdyates

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.