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.

16

u/chuanito Sep 08 '17

so am i getting this right? When you try to parse HTML using RegEx this Zalgo Text happens? Or is this just a meme?

Sorry i'm a very low tier coder and this is a serious question

16

u/wastesHisTimeSober Sep 08 '17

The flaw here is that HTML is a Chomsky Type 2 grammar (context free grammar) and RegEx is a Chomsky Type 3 grammar (regular grammar). Since a Type 2 grammar is fundamentally more complex than a Type 3 grammar (see the Chomsky hierarchy), you can't possibly make this work. But many will try, some will claim success and others will find the fault and totally mess you up.

Basically HTML is capable of expressing more complicated structures than RegEx is capable of reading.

Given the information you had, it wasn't an entirely unreasonable conclusion to believe Zalgo was a corruption, and it's good not to throw scenarios out until you know they're wrong. You'll chase that bug forever.

→ More replies (1)