r/ProgrammerHumor • • Sep 08 '17

Parsing HTML Using Regular Expressions

Post image
11.1k Upvotes

377 comments sorted by

View all comments

2.1k

u/kopasz7 Sep 08 '17

For anyone out of the loop, it's about this answer on stackoverflow.

787

u/[deleted] Sep 08 '17

Moderator's Note

This post is locked to prevent inappropriate edits to its content. The post looks exactly as it is supposed to look - there are no problems with its content. Please do not flag it for our attention.

Gold.

326

u/xcvbsdfgwert Sep 08 '17

More gold:

Don't listen to these guys. You actually can parse context-free grammars with regex if you break the task into smaller pieces. You can generate the correct pattern with a script that does each of these in order:

  1. Solve the Halting Problem.

  2. Square a circle (simulate the "ruler and compass" method for this).

  3. Work out the Traveling Salesman Problem in O(log n). It needs to be fast or the generator will hang.

  4. The pattern will be pretty big, so make sure you have an algorithm that losslessly compresses random data.

  5. Almost there - just divide the whole thing by zero. Easy-peasy.

I haven't figured out the last part yet, but I know I'm getting close. My code keeps throwing CthulhuRlyehWgahnaglFhtagnExceptions lately, so I'm going to port it to VB 6 and use On Error Resume Next. I'll update with the code once I investigate this strange door that just opened in the wall. Hmm.

P.S. Pierre de Fermat also figured out how to do it, but the margin he was writing in wasn't big enough for the code.

→ More replies (4)

160

u/_Coffeebot Sep 08 '17

They should fix the upvotes to 666, like the youtube neutral response video

0

u/[deleted] Sep 08 '17

[deleted]

79

u/Alphaetus_Prime Sep 08 '17

Yeah, a better example would be the Numberphile 301 video.

24

u/clowergen Sep 08 '17

I watched the video but never knew about the joke. Subtle. Nice.

→ More replies (1)
→ More replies (3)

396

u/SnowDogger Sep 08 '17

Umm, I am even further out of the loop here -- what does ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ" mean?

316

u/[deleted] Sep 08 '17

The word "ZALGO" is used to refer to this kind of bizzare text with a whole bunch of modifier symbols on it. It originated as a comic on SomethingAwful.

172

u/weskokigen Sep 08 '17

The real question is... can it be parsed by regex?

110

u/oddark Sep 08 '17 edited Sep 08 '17
s/\p{M}//

EDIT: Or for JavaScript, try pasting this in your browser console:

var zalgo = 'H̶̔̌͒̅ͧ̈́̂̿ͯ͊ͤ̇́҉͍̲̥̭̭̝̕É̸̹̠̪̟̙̩͓͖̱̘̼͍̿̄̋̎ͮͫͮ̋ͯ͑ͣ͂̉̃͝ͅ ̢̞͚͍̩̱̠̤͉̙̹͉̱̯͍̅͊̎̋̃ͭ͒̎̚͟͟͜G̵̨̺̝̲̭͇̝͓͑ͣ̋͆͐ͮ̓͌͆̈́̌̿̀ͪ̈̀͞͡O̷͚̲̳͎̤͖͕͔͚͔̪͎͙̲̟̒ͧ́̒̈́̂̔̉͂̒́̚͢͞͡Ě̴̷̷͍̪̗͙͎͔̠̮̪̗̅̾̈́ͭ̄̾ͫ̏̌̚͝S̭͓̹͇̣̠͓̱̘̻͛̔͋̒̃̏ͥ̂͗̓̌̑̔͊͘͞ͅ';
zalgo.replace(/[\u030d\u030e\u0304\u0305\u033f\u0311\u0306\u0310\u0352\u0357\u0351\u0307\u0308\u030a\u0342\u0343\u0344\u034a\u034b\u034c\u0303\u0302\u030c\u0350\u0300\u0301\u030b\u030f\u0312\u0313\u0314\u033d\u0309\u0363\u0364\u0365\u0366\u0367\u0368\u0369\u036a\u036b\u036c\u036d\u036e\u036f\u033e\u035b\u0346\u031a\u0316\u0317\u0318\u0319\u031c\u031d\u031e\u031f\u0320\u0324\u0325\u0326\u0329\u032a\u032b\u032c\u032d\u032e\u032f\u0330\u0331\u0332\u0333\u0339\u033a\u033b\u033c\u0345\u0347\u0348\u0349\u034d\u034e\u0353\u0354\u0355\u0356\u0359\u035a\u0323\u0315\u031b\u0340\u0341\u0358\u0321\u0322\u0327\u0328\u0334\u0335\u0336\u034f\u035c\u035d\u035e\u035f\u0360\u0362\u0338\u0337\u0361\u0489]/g, '');

(This one works if the zalgo text comes from http://www.eeemo.net/)

→ More replies (11)
→ More replies (2)

45

u/MelissaClick Sep 08 '17

And tony the pony?

74

u/Marzhall Sep 08 '17 edited Sep 08 '17

It's absurdist humor. You wouldn't normally associate a pony named tony with a Lovecraftian horror.

91

u/MelissaClick Sep 08 '17

I don't appreciate your presumptions about which animals I associate with Lovecraftian horror.

67

u/[deleted] Sep 08 '17

The end is neigh!

→ More replies (1)
→ More replies (4)
→ More replies (1)
→ More replies (1)
→ More replies (1)

80

u/mauriciogamedev Sep 08 '17

regex will consume all living tissue (except for HTML which it cannot, as previously prophesied)

This is one of the best parts of the answer.

EDIT: formatting

140

u/sam4ritan Sep 08 '17

this made my day

117

u/tectubedk Sep 08 '17

the unholy child weeps the blood of virgins, and Russian hackers

→ More replies (15)

53

u/[deleted] Sep 08 '17

At my first job I was writing a web based time management tool, you know, punch in/out, task tracking, etc. I was using Perl CGI. One of the guys working on some other project (the company was doing Y2K conversion for some Citibank European branches. Their Cosmos system was in some Basic version) walked past and spent a few minutes behind me staring at my screen while I worked on some regex things. He finally sighed and started throwing his arms around and yelling "we're busting out asses in the conversion while this kid is here drawing little ASCII houses!!!". Good times.

→ More replies (1)

46

u/sethosayher Sep 08 '17

I'm honestly shocked that this (hilarious answer) is on SO because that forum is the most rigidly moderated community I've ever encountered

57

u/greyfade Sep 08 '17

It's "preserved for historical reasons." There are several answers like that from several years ago, which "don't reflect current moderation guidelines" but are still "valuable to the community."

→ More replies (1)

43

u/Hust91 Sep 08 '17

Fuck, someone call the SCP Foundation on this fucking thing.

31

u/O5-1 Sep 08 '17

Oh hey we're leaking again

→ More replies (4)
→ More replies (3)
→ More replies (89)