4 ms·
So you'd be in favor of the question "What's the best regular expression for parsing HTML?"
by mark-r 7y ago
So you'd be in favor of the question "What's the best regular expression for parsing HTML?"
- gqcwwjtg 7y agoSure, there's a pretty reasonable answer about regex flavors with recursive extensions and how that makes them non-regular, which transitions nicely into a discussion of why you should just use a standard parser.
- ratww 7y agoWhy not? Like it or not, regexes are able to parse a limited subset of HTML. By explaining why they only can parse this small subset is a great teaching opportunity on Chomsky Hierarchies. And the people searching for it might learn that XML parsers exist. By actually giving an answer to the question (after saying the above of course) you might be helping thousands of people parse very simple HTML when they're in a hurry. By saying [1] you're just adding low-effort content on the internet that doesn't teach anyone anything, but make you look cool to your peers. [1] https://stackoverflow.com/a/1732454 https://stackoverflow.com/a/1732454
- mark-r 7y agoAnyone incapable of writing their own regular expression for this is unlikely to know when their problem is too complicated to be solved by it. You're not actually doing them a favor by answering the question.
- ratww 7y agoThat's bullshit. By explaining to them Chomsky Hierarchies they can understand limitations of regexes and learn about parsers and. By showing them the regex able to parse a limited HTML subset they might be able to try it out and see such limitations by themselves on their own screen. Additionally they might be able to learn some new regex tricks. Maybe you learned things in a different way, but lots of people enjoy learning stuff by doing and by seeing demonstrations.
- yongjik 7y agoThat's one of my all-time favorite answers on stackoverflow, and it doesn't exactly look low effort. It would probably take more time to write something like that than write about Chomsky Hierarchies. Besides, I concede that "helping thousands of people parse very simple HTML when they're in a hurry" has its merit, but IMHO that's also how you end up debugging a production bug at 3am while losing faith in your fellow developers and humanity, so I'm not sure if it's a net plus. YMMV.
- ratww 7y ago> It would probably take more time to write something like that than write about Chomsky Hierarchies. And yet it is not only wrong, but the answers below do a much better job at explaining Chomsky Hierarchies and other things correctly. Why is it wrong? "Have you tried using an XML parser instead?" is wrong because HTML is not necessarily XML/XHTML. The first working draft of HTML5 was published a year before that answer, and non-XML websites existed since the 90s, so there's no excuses. - > but IMHO that's also how you end up debugging a production bug at 3am while losing faith in your fellow developers and humanity, so I'm not sure if it's a net plus And that's why you treat people like adults: you tell them the limitations of each method, instead of making a meme. And btw, you can get bugs at 3am with a XML (or HTML) parser too.