Remix.run Logo
ruhith 5 hours ago

The real punchline is that this is a perfect example of "just enough knowledge to be dangerous." Whoever processed these emails knew enough to know emails aren't plain text, but not enough to know that quoted-printable decoding isn't something you hand-roll with find-and-replace. It's the same class of bug as manually parsing HTML with regex, it works right up until it doesn't, and then you get congressional evidence full of mystery equals signs.

lvncelot 5 hours ago | parent | next [-]

> It's the same class of bug as manually parsing HTML with regex, it works right up until it doesn't

I'm sure you already know this one, but for anyone else reading this I can share my favourite StackOverflow answer of all time: https://stackoverflow.com/a/1732454

perching_aix 3 minutes ago | parent | next [-]

It took me years to notice, but did you catch that the answer actually subtly misinterprets what the question is asking for?

Guy (in my reading) appears to talk about matching an entire HTML document with regex. Indeed, that is not possible due to the grammars involved.

But that is not what was being asked. What was being asked about are the individual HTML tags. To my knowledge, those are very much workable via regex, and there's no grammar capability mismatch either.

josefx 4 hours ago | parent | prev | next [-]

I prefer the question about CPU pipelines that gets explained using a railroad switch as example. That one does a decent job of answering the question instead of going of on a, how to best put it, mentally deranged one page rant about regexes with the lazy throw away line at the end being the only thing that makes it qualify as an answer at all.

kapep 4 hours ago | parent | next [-]

The regex answer is from the very old days of Stackoverflow, before fun was banned. I agree it barely qualifies as answer, but considering that the question has over 4 million page views (which almost puts it in the top 100 most viewed questions all-time), it has reached a lot people. The answer probably had much more influence than any serious answer on that topic. So I'd say the author did a good job.

bobince 3 hours ago | parent | next [-]

Of all the things I wrote on SO, including many actually-useful detailed explanations, it was this drunken rant that stuck, for some reason.

scott_s an hour ago | parent | next [-]

I think of, and look up, this drunken rant at least once a year.

falcor84 2 hours ago | parent | prev [-]

And for that I applaud you.

I know it's a hassle for a platform to moderate good rants from bad ones, and I decry SO from pushing too hard against these. I truly believe that our industry would benefit from more drunken technical rants.

DangitBobby 3 hours ago | parent | prev [-]

People have shared it here and on reddit a bunch of times because it's funny. I always found the pragmatic counter-answer about using regex and the comments about how brittle it is to parse XML properly assuming a specific structure to be much more useful.

MrGilbert 4 hours ago | parent | prev | next [-]

For anyone wondering about the railroad switch post: https://stackoverflow.com/questions/11227809/why-is-processi...

operator-name 41 minutes ago | parent [-]

This is new to me, and a wonderful dive that I wish I was aware of during my OS course. Thanks!

bityard an hour ago | parent | prev [-]

But--and this is crucial--the one about regexes is hilarious.

It also comes from a time in Internet culture when humor was appreciated instead of aggressively downvoted.

Cthulhu_ 4 hours ago | parent | prev | next [-]

HE COMES

bayesnet 4 hours ago | parent | prev | next [-]

I know this is grumpy but this I’ve never liked this answer. It is a perfect encapsulation of the elitism in the SO community—if you’re new, your questions are closed and your answers are edited and downvoted. Meanwhile this is tolerated only because it’s posted by a member with high rep and username recognition.

1718627440 3 hours ago | parent | next [-]

I think this answer was tolerated when SO wasn't as bad as it is now, and wouldn't be tolerated now from anyone.

bombcar an hour ago | parent [-]

It's because SO at the time was a small high-trust society where "everyone knew each other" and so things flew back then that wouldn't fly now.

throwaway_61235 3 hours ago | parent | prev [-]

As someone who used to write custom crawlers 20 years ago, I can confirm that regular expressions worked great. All my crawlers were custom designed for a page and the sites were mostly generated by some CMS and had consistent HTML. I don't remember having to do much bug fixes that were related to regular expression issues.

I don't suggest writing generic HTML parsers that works with any site, but for custom crawlers they work great.

Not to say that the tools available are the same now as 20 years ago. Today I would probably use puppeteer or some similar tool and query the DOM instead.

vbezhenar 26 minutes ago | parent | next [-]

An interesting thing is that most webpages are generated using text templates. There's some text processing like escaping special characters, but it's mostly text that happened to be (somewhat) valid HTML.

So extracting information from this text with regexps often makes perfect sense.

wat10000 an hour ago | parent | prev [-]

I would distinguish between parsing and scraping. Parsing really needs a, well, parser. Otherwise you’ll get things wrong on perfectly well formed input and your program will be brittle and weird.

A scraper is already resigned to being brittle and weird. You’re relying not only on the syntax of the data, but an implicit structure beyond that. This structure is unspecified and may change without notice, so whatever robustness you can achieve will come from being loose with what you accept and trying to guess what changes might be made on the other end. Regex is a decent tool for that.

umanwizard an hour ago | parent | prev [-]

Funny how differently people can perceive things. That's my least favorite SO answer of all time, and I cringe every time I see it.

It's a very bad answer. First of all, processing HTML with regex can be perfectly acceptable depending on what you're trying to do. Yes, this doesn't include full-blown "parsing" of arbitrary HTML, but there are plenty of ways in which you might want to process or transform HTML that either don't require producing a parse tree, don't require perfect accuracy, or are operating on HTML whose structure is constrained and known in advance. Second, it doesn't even attempt to explain to OP why parsing arbitrary HTML with regex is impossible or poorly-advised.

The OP didn't want his post to be taken over by someone hamming it up with an attempt at creative writing. He wanted a useful answer. Yes, this answer is "quirky" and "whimsical" and "fun" but I read those as euphemisms for "trying to conscript unwilling victims into your personal sense of nerd-humor".

chucksmash an hour ago | parent | next [-]

There's nothing that brings joy into this world quite like the guy waiting around to tell people he doesn't like the thing they like.

philistine an hour ago | parent | prev [-]

The whole argument hinges on one word in your post: arbitrary.

I parse my own HTML I produce directly in a context where I fully control the output. It works fine, but parsing other people’s HTML is a lesson in humility. I’ve also done that, but I did it as a one time thing. I parsed a specific point in time, refusing to change that at any point.

umanwizard an hour ago | parent [-]

It also hinges on another word: parsing. There are things other than parsing that you might want to do. For example, if you want to count the number of `<hr>` tags in an HTML document, that doesn't require parsing it, and can indeed be done with regex.

kstrauser a few seconds ago | parent [-]

No you can’t. You can have an unescaped <hr> inside a script tag, for example. The best you can do is a simple string search for “<hr>” and hope it’s returning what you think it might be returning. Regexps are not powerful enough to determine whether any particular instance of “<hr>” is actually an HTML tag.

Like, it’s not a matter of cleverness, either. You can’t code around it. It’s simply not possible.

ErigmolCt 29 minutes ago | parent | prev | next [-]

And because the output still looks mostly readable, nobody questions it until years later when it's suddenly evidence in front of Congress

V__ 5 hours ago | parent | prev [-]

They have top men working on it right now.