1. I didn't provide the solution, I commented on it
  2. I don't have low standards for code - I suggested a different solution space (HTML::Strip or HTML::Parser) if this wasn't a one-off. Not all one-offs need to be robust.
  3. I gave an example of three places where the solution was "broken" - script and style tags, tags nested in comments (illegal but common) and doctype declarations.
  4. I make a suggestions for fixing those three specific issues.

Your point is taken, though - I don't say why I still don't think that the ammended solution is robust. Parsing HTML with a series of regexes is slow and difficult. style tags don't necessarily have endtags, for example: They could simply have a link to a .js file. Then, much later in the HTML document, if there was a closing script tag for another block, it would swallow and delete the enclosed valid content.

For performance, HTML::Stripper is an XS module, so it would be much, much faster than the multi-pass regex approach.


In reply to Re^4: Stripping HTML tags by fishbot_v2
in thread Stripping HTML tags by Anonymous Monk

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.