3 comments

  • danlitt7 hours ago
    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.
    • layer86 hours ago
      Some commenters are missing that this is a reference to <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1732454" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1732454</a>.
      • chrisandchris5 hours ago
        &gt; Locked. There are disputes about this answer’s content being resolved at this time [sic]<p>And also<p>&gt; Nov, 2020<p>And then, StackOverflow asks itself why it looses users.
        • layer85 hours ago
          The answer is actually from 2009. As long as HTML&#x2F;XML doesn’t suddenly become a regular language, I think it’s pretty timeless.
        • magicalist5 hours ago
          It&#x27;s a 17 year old joke, maybe one of the most famous on stackoverflow for the aging engineers out there. No one wants new &quot;funny&quot; edits on it.
      • pwdisswordfishq6 hours ago
        Good ol&#x27; appeal to emotion devoid of technical argument.
    • rokkamokka7 hours ago
      You can parse a subset of it though, like if you&#x27;re in control of the html yourself and avoid certain structures
    • zarzavat7 hours ago
      Parsing HTML with a regex is never a good option, but it&#x27;s sometimes the only option.
      • pkal7 hours ago
        In the example from the article it certainly is an option. In Python you could either use a &quot;soup&quot; library or you could play around with a tool like <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;Tools&#x2F;HTML-XML-utils&#x2F;man1&#x2F;hxpipe.html" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;Tools&#x2F;HTML-XML-utils&#x2F;man1&#x2F;hxpipe.html</a>.<p>The more fundamental question for me is why the author didn&#x27;t decide to make make code blocks non-breaking by default, or just add the class annotations when he writes the HTML?
    • tyho6 hours ago
      You can absolutely parse HTML with regex, so long as the document is finite in length. Every finite language is regular, hence can be parsed with regex&#x27;s.
      • magicalist5 hours ago
        Zalgo and situational subset parsing aside:<p>&gt; <i>You can absolutely parse HTML with regex, so long as the document is finite in length</i><p>This isn&#x27;t sufficient, unless I&#x27;m misinterpreting what you&#x27;re saying. It&#x27;s not enough to have documents of finite length (all documents <i>are</i> finite in length), you need documents with a <i>max</i> length, so you have a finite number of possible documents to parse.
      • gpvos6 hours ago
        Do a web search for the parent of your comment, read the Stackoverflow answer. It&#x27;s a classic. Learn about Zalgo and Tony the pony, he comes.
    • matheusmoreira7 hours ago
      Tony the pony, he comes.
    • timedude6 hours ago
      What do you mean you can&#x27;t. I do it all the time
    • prmoustache6 hours ago
      I do not count substitution as &quot;parsing&quot;
  • pwdisswordfishq6 hours ago
    Why even bother with the CSS class? Just apply text-wrap: nowrap; to all &lt;code&gt; elements and dispense with the fragile regex parsing.
  • pimlottc6 hours ago
    Unfortunately this makes it much harder to read on narrow-width screens (e.g. mobile), where the use must scroll horizontally