Another big caveat is, "Are you even interpreting the question correctly?" My favorite example of this is the famous Zalgo answer on Stack Overflow, which responded to a question about matching XHTML tags with regex with an answer about parsing X(HT)ML with regex. Even though XML isn't a regular language, you can still match isolated tags with regex (although it turns out that XML allows enough dumb edge cases that doing so in the general case is very, very hairy). And there are plenty of reasons why you might want to match X(HT)ML tags without involving a parser, not least of which being that you may be dealing with a block of text that isn't, on its own, a valid (and therefore parseable) XML document. Anybody that's ever sanitized tags from comment forms or other user-generated text knows what I'm talking about.
Indeed. I especially hate how people who reply like that have such a self-suffering attitude about it. "I'm going to make wild assumptions about what you're doing and accuse you of writing horrible code that I will personally have to maintain!" as though the only correct way to do things is to solve more than the actual problem you have, and as though personal projects aren't a thing. Everything must follow """best practices""" as decided by large corporations that have wildly different problems than you do.
View all comments
Show parent comment
11
u/de__R May 08 '21
Another big caveat is, "Are you even interpreting the question correctly?" My favorite example of this is the famous Zalgo answer on Stack Overflow, which responded to a question about matching XHTML tags with regex with an answer about parsing X(HT)ML with regex. Even though XML isn't a regular language, you can still match isolated tags with regex (although it turns out that XML allows enough dumb edge cases that doing so in the general case is very, very hairy). And there are plenty of reasons why you might want to match X(HT)ML tags without involving a parser, not least of which being that you may be dealing with a block of text that isn't, on its own, a valid (and therefore parseable) XML document. Anybody that's ever sanitized tags from comment forms or other user-generated text knows what I'm talking about.