up vote 0 down vote favorite
Share on Facebook

How would you build an HTML parser using RegEx?

link|flag
@Robert Harvey, so php4 is the best option for implementation language then? – instanceofTom Dec 2 at 23:35
@instance: Perhaps (I deleted my obligatory "Ghost Busters" reference). – Robert Harvey Dec 2 at 23:38
What was the point of posting what is obviously just a reference to the SO question? – Jon Hopkins Dec 8 at 16:13
@Jon what is the point of commenting? – Alison Dec 11 at 3:19
@Alison - I asked a question. I don't know about you but I usually to that to elicit an answer. – Jon Hopkins Dec 11 at 14:05
show 3 more comments

7 Answers

up vote 16 down vote accepted

As the first person here, it's my responsibility to post this.

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts. so many times but it is not getting to me. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing HTML. You will never make me crack. HTML is a language of sufficient complexity that it cannot be parsed by regular expressions. Even Jon Skeet cannot parse HTML using regular expressions. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing HTML with regex summons tainted souls into the realm of the living. HTML and regex go together like love, marriage, and ritual infanticide. The <center> cannot hold it is too late. The force of regex and HTML together in the same conceptual space will destroy your mind like so much watery putty. If you parse HTML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes. HTML-plus-regexp will liquify the n​erves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Rege̿̔̉x-based HTML parsers are the cancer that is killing StackOverflow it is too late it is too late we cannot be saved the trangession of a chi͡ld ensures regex will consume all living tissue (except for HTML which it cannot, as previously prophesied) dear lord help us how can anyone survive this scourge using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes using regex as a tool to process HTML establishes a breach between this world and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but more corrupt) a mere glimpse of the world of reg​ex parsers for HTML will ins​tantly transport a programmer's consciousness into a world of ceaseless screaming, he comes, the pestilent slithy regex-infection wil​l devour your HT​ML parser, application and existence for all time like Visual Basic only worse he comes he comes do not fi​ght he com̡e̶s, ̕h̵i​s un̨ho͞ly radiańcé destro҉ying all enli̍̈́̂̈́ghtenment, HTML tags lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq​uid pain, the song of re̸gular exp​ression parsing will exti​nguish the voices of mor​tal man from the sp​here I can see it can you see ̲͚̖͔̙î̩́t̲͎̩̱͔́̋̀ it is beautiful t​he final snuffing of the lie​s of Man ALL IS LOŚ͖̩͇̗̪̏̈́T ALL I​S LOST the pon̷y he comes he c̶̮omes he comes the ich​or permeates all MY FACE MY FACE ᵒh god no NO NOO̼O​O NΘ stop the an​*̶͑̾̾​̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨe̠̅s ͎a̧͈͖r̽̾̈́͒͑e n​ot rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ

--- Have you tried using an XML parser instead?

link|flag
You linked to the wrong answer, my friend. – Robert Harvey Dec 2 at 23:34
Haha I know, I blew it. Fixed. – nlawalker Dec 2 at 23:34
2  
"Even Jon Skeet cannot parse HTML using regular expressions." I love it. – tcrosley Dec 3 at 0:35
1  
If you didn't post it, I would have. Have some points. – Inaimathi Dec 3 at 3:09
2  
@Josh: Bobince is going to come after you for copy-pasting his answer here. I hope you're prepared. – Robert Harvey Dec 3 at 7:04
show 2 more comments

jQuery, obviously.

link|flag
2  
+1 because jQuery is the Chuck Norris of JavaScript – Gary Rowe Dec 6 at 22:34




P̞̰̟͂ͭ̐́͑̀̏͐̽̔ͅr̼̜̠̼̼̦̭͎̺̤̺̭̮͛͗̔̒̋ͯͤ͑ͨ̐ė̦͍̜͙̯̣̲͚̯̐͆̽͆́ͣ̊͊̔͐t͈̼͉̣͚͇̤̦͙̺͈̦̩̦̙̲͔ͭ̽̉̏ͤ̔̉ͦ̒͑̎̅t̟̙̬̼̞͉̖̺̘̦̺͇̞̞̲̬̼ͥ̉ͪ͗̂̓̓̑̿̏́̐̄͂ͥ̓͌ͅẙ͎̮̼̯͙̗̯̻̗̯̞͇̈ͫ͒̋̋̄ ̪̦̗̻͕̬̣̀̈ͭ̏ͨ̅ẹ̬̼͇̜͉̰̻̩̼͎̮̙ͤ̈ͧ̈́̅̇̊̐͛̚ḁ̦̞͎̩͙̟̠͙͓͖̄͗̎̄ͬ͑̍̒̉s͖͔̠͎͙̣͉͇̜͕̺̩̺̫̙̯̲͉̪̉͐ͮͨ̐̊͐̃̓̂i̳̬̘̓ͫͫ̃ͨ̉͆̽̎̚ͅl̲̳͙͚̻̑̃͗y͓͇͉̮͇̺̘͓̥͕̼̝͊ͣ̃ͤ,̜͙͖͍̬̮̯ͭͬ̒ͫ̎̓ͨ ͖̗̹̖̣͔ͫ̄͗̆̿ͩ͐̿͒̾̈̍́̈͛ͪ̚ͅa͇͕̫̱͍̞̬͚̺͇̿ͪͬ̈́̍ͧ̓̽͂͂͋ͭc̳͇̫̮̳͖̮̈͛ͥ̄ͯͭ̈ͣ̄̒̈ͥț͉͓͕̭͓̥̫͎̜͈̺̬̳̪͚͗̍̽̿͋̋̓̉͑ͤ̋ͯù̫͓̟̙̪̲̟̘̪̪̪͉̭̘̗̝̬̊͒̌ͫͦ̆ͤ̓̾͌̎̚̚̚ȁ͓̳͚͙̝̩̟̹͚͎͍̬̪̳̺̩ͮ̋ͥͣ͂͒ͯ̇͐̃̓̆̆̿͌̂͒ͣͅl̘͎̫̣͖͔̣͚̹̬̦͔͆ͫ̾ͩ̂̈̽͛ͫ̄ͦ̀͐ͣ̓̚ͅl̜͖̭͕͚̦̹̻̠̹̠̰̝̹̇̒ͩ́̑͗ͦ̐͊̾̆́ͦͧy̝͇̖̮̞̰̙͔̳̦̍ͬͯͨ̾ͨ̂ͣ̆̾̒͛̊ͪ̿̿̀͋ͥ.̱̯̭͓̲̻̩̤̙͖̘̊͛͌͂ͫͦͮ͊̉͂ ̖̣̟̦̙̰̦̟̖̓̄̽̉̃ͨ̓̅̎͂͐̇ͥͫͮĔ͚̬̯̯̠͇̻̞̘̺̟̪̙͉̯̼̤̙̓ͪ̂̒̑̉̾̓ͭͧ͐ͥͯ͛ͫͅx̞̰͓̘̺͎̤͒͆̃̽́͌̍̎͋ͭ́ͦ͗ͦ͛ͪc̞̠͍̲̻̫̗͇͉̳̲̟̳̿ͬ̃̈́̐ͬ̽ͯͩͧḷ̠̞͍͍̅̄ͦ͛͐͒ͬu̠̯̻̥͓̺̦̦̼͚̯͈͓̻͇̎ͭ̆ͫͣ̅̀̓ͪ̊̂͂̓́̉͋̇ͩͅd͓͙̦͔̭͚̠͈̜̹̠̰̠̥ͭ̎̑̃̏̏ͬ̈ͯ̓̎̈́̐ͫ̈ͅi̮̜̱̖͚̺̫̝ͪ̽ͦͮ̇̂ͬ̍ṇ̜̦̪̬͓̱͉͓͚̈̇͒̋ͮ̊̂g̲̬̤̝̙̐̾̓ͪ͒̏ͬͦͫͨ̃͊ͅ ̳̮͕̗̞͉̟̰͉̞̬̺̟̤͉ͧͦ͗ͧŝ̭͙̬͕͍̭̹̘͓̞͇̼͔̯͚̫̈́͑̆͑̾̂̎̋ͥ̀̎ḙ̥͖̺̫̗͎͖͎͕̣̬̗̙̻ͬ͛̓ͣ̆̎̈́ͅl͎̩͉̠̖̜̫͕̳̰̤̰̣̝̫̯͎̥ͮͥ͆̎͐̄ͬͣ͊̐ͧͩ̈́̄̎̓ͪ̚f̰̬͍̫͔̼̰̳͚̥͙̝͍͊ͤ̽ͨͭ̀ͮ-̟̱̬͔͙͖̯̫͔̝̬̖͕̮̮̙̬͚͗͂͒̑ͯ̾͑̍ͨͯ̀̐̐ͨͤ̏͒ͮͅc̪̥̘͚̙̟̘͉̭̜̹̏͋̐ͣͭ̊́͑̿̎ͩ̍̔ḹ͔̭͔̞͓͎͔͖̯͓̒̈ͩ̃͋͛̚o̭̤̣̰̤̹̝̺͓͇̹̰̙̖̟͇ͩͫ͌̈s̪͉̫͍̣͉͛͊̓ͤ͒̌̄ͦ̿ͥͩ̊̈́ï̠̟͔̭͖̼̰̝̰̙̳̻̟͎̝̘͕̠̈́̾̿̅n͍͇͕̗͍͈̭̙̒̃̏͋̎̏̈͒̀̏͐̔̔̉̚g̠̠̱͇̠͔̜̜ͥ̒ͫ͆̒̍̑̾̌̋̋̓͛ͯ͊ͥ̓͐ͥ ̭̥̮̦̯̪͇̟̦̥̹̩̺̗̜̭̟́̈̎̀̋̏ͥ͛̏ͪ̊̄̃ṭ̻͚͙͔̳̘̲̣̀́́̍͆́̌ͫ͊̓ͥͪ̃̈́̎͊̚a̭̦̪̺͇͖̘̙̲͇̠̼̔ͧ͒̇g̦̺̰̘͉̣͙̟͚̦̬̼̯͙̣ͧ̐̉̄͊̒ͅs̫̯͇̟̟̮̪͍͚̯̝͚ͥͧ̆ͮ̍͒͑̇͗͛̽̋ͯ͒͊̊͗̚̚,̥͕̞͖͙̺͖̥͇̟̜̓ͦͭ̐̓ͅ ͓̠̯͕̞̻̼̳̰̭̬̇͋̎ͣ̎̎̉̌ͣ̎ͤ̋̀̄͛̈̐̈ͅͅa̝̱̣͈̞̩̭̖̪̟͈̣̗̺̳͕͈ͥ̾̌̔͌̉ͦͭͫͣͫ͛̓ͮl̫̘̙̼͓̖̝̠̖͓̐ͤ͊ͅl͇͉̙̱͈͎͖̜̙͇̞̻ͮ̅̏̃ͫ͋̉̓ͬͩͭ͗̌͂ ̰̫̬̣͙͂ͨ̓̌ͭͪͅy̝̤̰͙̱̗̮̖̤͉̮͚̩͙̒͋̋͂̊̄o̬̫͕̯͚̮͓̪̠̭̞̝̟̩̗ͫͪ̓͌͋ŭ̥̙͈̭ͯͫͨͣͭͪͣ̓ͮ͂̿ͮ̈̉ͮ̐͋ ̫̩̫̣̈́̇͆ͥ̅͑̒͆ͭ͒͂͂̚̚ͅn̹̻̻̜͖͎̝͖̰̭̠̦̩͙̤̲͍̄ͭ̌͗ͣ̐̋ͤ̅̈̂̒̈́̄̏ͪ̓̉ͅĕ̻̦͔͎̯̳̭̍ͫ̆ͭ̊̆̈̃̉̚̚e̜̰̥͎͖̗̲̗̙̦̹̦ͥͮ͑ͭͧ̂ͅͅd͕͖̰̫͖̺͉̠͕̖͇̗̺̜͉̟̺̬̩̐̄̊ͤ͗̋͂̈̽͑͊͂͆ͨ ̳̰̰͖̜͎̘̮͓̩͚̘̯ͬ̍͌̑̇̐́ͮ̈͂ͦ̌ͪ̽̍̚ṫ̰̮̗͖̻̼̪̠̼̙̘͇̦̲͙̳͔̣̰ͪͨ͛o̥̙̠͖̻̣̹̘̻͓̺̱̮̙͛ͥ̀͊ͮ̈̓̏̓̔͋̓ͬ ̱̼̳̣̬̲͈͕̱̟̲͎͔͈̫̓ͬ̽ͤ͂̾̓̿͒̈́̄͒̚ͅd̳͓͍̳̜̦̗̑̐ͯ̇̎ͤͦ͌o̯̺̺͍̩͚͕̙̝̤̓ͤ̓̔͛̓̽̽ͭ̃̄ͨ͋̒ͅͅͅ ̺͕͍̝̠̔͑̊̋ͮ̍͐ͤ̿ͨ̒̄̉̏̂͋̎̾͗i͎̗͎͖͇̼͍͚̹͚̲͕̞̤̭͌́̾̎̂̿ͦ̃̽͋͌ͯͮͩ̆̏̂ͥs̜̫͓̝̯̗̹̳͔͉̹̩̜̼͈̓̓̈́ͩ́͂̈ͅ ̮̙̠͎̣̦̪͎̬̻̾̃̎̉̒ͩ̃ͤ̀̉ͬͥ̄ͤm̖̩͕̮̘͔̯̙̣ͣͪͫͥ̓͂̏͌ͧ͆ͪ̇̾ͅȧ̞̬̯͎͎̬̺͔͙̳̰ͧ̆͆ț̰̫̹͉̺̜ͭ̓͂ͯ̃͐̋̓̅ͣ̒̐c̝̬̰͕͎͕͕̹͍̼̳̤̗͖̤̣̹͛ͧ̃ͭ̉̽̆ͮͣ͗̃ͨ͋̍͌ͨͪͅh̲̥̥͙̭̲͕̖̙͎̟̺͕͙͍̰̙ͬͯ͑͛ͮ ̲̱̟͖̳̾ͬ̊ͦͯ̋̊̒͑̍͑ͅa̲̮̜̥͖̳̭̙͍͔ͨ̄ͥ̋̐̚̚n̤̦͖͉̟̞͒ͦͦ̈́͐͆͆̆ͨ̐ͣͦ̑̄ ̟̖̻̤͎͇͚̤̫̤̮͓͋̈ͬͩ͗̏ͦͭͤ̒ͦ͛̉̚o͕͎͓̤͎̺̰̙̯̼̓ͮ̓ͤ͊ͮͥͅp͎̯̫̞̬̬̠̰̤̜̼̱̭̀ͥ̽̌̉̎̌e̥̮̫͓͙̲̯̹͍͇̍̋͂̍͋̊ͦ̋̇͑ͭͤ̅͑̚ͅṋ̥͓̮ͦ̍͆͂͑̒̈͑ͫ̑ͮ̂ͫ̾̀͗̓i͕̭̭̠͕̟͎̦͔̼̼͇̹̫͚̘̺ͩͯ͗̑ͤ͑́̂͌̃͑ͯ̍͑ͥͣ͋͑̈ṋ̜͍̯̦̭͕̲̮̻̟̞̪̓ͣ͂̆̐͊̾ͮ̔̇̾̈͛̎̂ͬ̚ġ̰̰̠̙̪͚̫ͭ̂͋̌̆̒̒ͥ̾ͧ̄̑̃̾̔̏̒ ̦̞̠̪̫͎̲̜͎̲̮̬͙̱̥ͦ̋̓̊͑ͪ̉̈́ͭ͆t͈͙͎̺̦̩̫̣̫̜͇͓̗̂̂̅͆͒ͨ̂͋̎̍ͣȃ̘̟̝͍͖̫̲̩̖̦̻̼̫̙͆͋̒ͭ̽̈͌̊ͦͩ̋̉̚g͈̜̫̯̥̘͖͎͖̹͇͖͇͂̈̏̾ͬ͂,̯͔͍̳̬̥͇̟͎͋̔̽͌ͪ́̽͊̂̾͑̅̄̿ ̜͎̪̖̜̲͖̠̜̗͚̼̩͈̲̯̯̱̓̒ͮͥ̍͌̌͊̀͋̆ͧͪ̋̓͆ͅw̰̟͔̙̞̮̙͇͍̰͓̝͙̲͍̔̑̐ͨ́̐̂̓͗ͭ͒ͅh̹̫̞̟̳̱̹̦͙̻̗̰̞ͩ͗̌̏̏ͧͫ̽̌ǐ͍̦̮͕̔ͩͪͫ̎̑̐̓ͪ͂̔̃ͬͅc̺͉̟̝̣̖̦͊͛̂̋̚ȟ̬̫̯̹̣͇̺͑ͮ̏ͫ̽̋ͬ̓ ̟̹̯̥̖̥̦̙̟̺̄ͫ͐̉̔̂ͥͥ̾ͅm̳͚̤͖̱̪̹͔͓̲̗̖̏̀̿ͨͬͣ̓̑̍̋̂͂̍ā̯̰̯̳̇͆̆̉ͥ̆̍̈́ͦͣͫy̘̠̠̭̜͎̜͊̍̋̑ͮ̂͆̅ͭ͒͊̚ ͔̫̩͍̹̫̘̜̼̪̘̮͇̦ͤ̋ͮ́̂͑̍̈̇͛̄̉̀ͨ͑̄̊ö̘̻̱͉̟͍͓̪̼͈̮͎͈̖̗̠̹͐̿̔̉̂̈́̾͐͌̂̌ͫͧ̈́̄r̯̣̲͚̮͗͛̆̑ͣͣͦ͊̍͌ͮ̓ͧ̇̀̑̾ͫ ̘̘̖̭̖͖̐ͦͤ̽̽ͤͨͫ̂ͨ̽̄̓̅͐̒ͭͯ͐m͉̬̭͓̖̝̗͈̻̘̫̙̿̏͌ͩ͂ͬ̚a̠̣̞̘͉̩̯͚͇̤ͦ̀ͩ̍̀ͮ͑ͥͮ̐̃ͯͫ̋ͅy̬͈͍̠͛̂ͣ̄̓̅ͯͪ̉ͭ̔̓̌̿ͫͦ̚ ̭̹̗̲̥̤̟̯̣͎̫͕͓̮̠͙̅̌̒̈̿n̬̳̗̱̟̪̳̫̺̈ͭ͒̏̍̑̉̾̔̆ͣ̐͌̿̄̈̚o̼͕̪̳͇̫͕͉͙̜͓̞͈̬͌̅ͫ̓̀́͗ͬ͑ͫt̥̖͎̼̻̗̬̯̉̈̂ͪ͒̽̐̇̏̆ͭ̅̃ ̝̮̻̣̗͎̦̼̹̻͉̼̜̟ͩͪ̓̓̇͛͌̍̽ͥ̋̈̂ͅͅh̟̠̥̞̰͔͎ͫ̃͆̀ͯ̈̈́́ͨͤͯ̊ͨ̑̍̅ͩ̄a͇̙̪̜̱̹̳̜̖̪͕̞̼͙̍̄̅̋̐͋ͨ͋ͪ͊̉͐͌ͤv̬̜̖̱̺̒̈́͌ͬ̌ͦ̈ͅe̤̞̞͙̙͓̐͑͒̓̂̌̎ ̻͈̬̺͎̦̘̘̯̱̤̼͈̗̮̱̑̐͐͒͒ͣͬ̑a̗̮̫͈̗̮̭͇̲̜͙ͣͦͤͮt̲͚̼̟͍̠̗̘̻̪͖̯ͧ̾̈̈ͯ̔͋̇̅̚ͅt͎̥͇̹͚ͫͤ͗̓ͯ̾͐̓ͬ͊͛͐̈̓̊ͤ͌̚ͅr̟͓͇̠̝̬̹̙̊ͩ̿ͫ̇̾i̼̟̙̠̰̲͊̐̔ͤ̅ͬ̾̓̋͗͐̂́ͪ̏̌ͨ̚b͖͚̹͇̩͈͎͎̼͂͗̽͑̄͛ͧͧ͋̔͑̋̆́u̥̘̰͍͕͍̪͚̹̥̻̭̹͇͇͇̒͐͂̽̐͗ͫ̓̒̓̀͊̐ͩͬ̒ṯ̭̻̦̪͙̩̞̝͇̤̈́ͭ̄̊ͮ͋̅̽̒ͩ͛ͪ͒̈́e͖̭͙̘̝͎̹͈̙͉̹͚̐̒ͦ͐ͦ̎s͍̠̱͑̒̀ͬͧ̌͋̏ͩ̂̊̂,̥̖̝͔̼̘̺͖̟̔̎͂̑̾̓̈ ̥̟̻̰̼̘̮̙̳̱̼͙̼͉̜̯̮͓͂ͦ̽ͧ͌̂͛ͬ̌͛a͔̬͖̘̪̪̹̰̩̗͇̺̰̓ͯͩ̅ͣ̎̐̍ͩ̂n̝̞̤̬̩͙̗͈̬̫̮̭͉̰̲͎ͦ̿̎ͤ̐ͮ̊̿͆d͉̜̫͉͛̋̇ͤ̊̾ ͇̝̖͖̝̣͕̖͖͙̺̞̯͚̩̌ͨ͋̇͌̄͐̏ͬͥͭi͍͖͖͒ͥͫ̑̌̒̒̒̍ͪ̆͆̚̚t̗̜̺̰͇̱̪͉͖͕̦͇̟͎̯͖̙̳͑ͣ͐͒͂̿́̊̐̅s̥̫̹̤̯̞͍̥̹̬̹͇̭ͣ̎̊ͭ͊ͅ ̻̜̙̹ͧ̑̍̇̇̊ͤ͛ͤͦ̑̍ͅc͉͎̮͕̲̺̭͖̻̪͙̼̣ͫ̔ͧͫ̓ͪ̔ͣ́͊̿ͤ̍̚ͅḽ̩̣̟̯̲̗͍͍̰̫̥̭͕̣̗̳̏̓̑̽̆͋̀̋ͬ͂͌̔ͯ͗ͅo͇͖̪̼̮̳̲͚̣̳̺̠̭̯̓̈͒̔ͪ̔̽̔͑̊ͭͧͣ̔́̌̐̄ͤs̜̞̗̱̩̰̼̘̙̻̾̽ͬ͂ͮͬ̃̐̎ͤ͌ͯ̿̿̅ͪ͑͋i̦̙̯̘̱̳̅͛ͭ̏͒ͪn͈̖͈̭̹̦̰͈̜̺͚̩̫͚̺͈͓͔̼̽̂̑̓̈́̃ͤ̃͑̿̐ͭ̋̆ͣ̒̌̋̚g̲̥̞̠̭̼̪̻̗͇͇͐͒̔ͣͥ͋̄̑͐͆͐̔̐̃̉̂ ̭̥̳͔̲̥̠̙̞̤̩͍̈̇̓̓͑̔̅ͭͅt̹͍̝̻̞̩͔̝͔̜̭̪̃̄͒͆ͧ͑̒̇͐͆̌̒̚a͔̭̯͉̥̰̬̞͇̮ͬͦ͋͊̅̉ͬ̿̒̊ͯ̐͂͂́ͅͅg̳̪̖̦̺̬̩̪͇͉̱̟͆͒̌ͧ̽ͧ̈̌̓ͨ̅ͭͥ.͍͈̘̰̭͚̺͚̮̺̲͖͇̦̔̏͒̈͗͗ͣͭ̍̋͋ͥ̽ͤͫ̒̈͋ͤͅ


link|flag
9  
All I see is blonde, brunette, redhead.... – Robert Harvey Dec 2 at 23:38
You hacked the internet. :O – Nathan Taylor Dec 3 at 1:17
Now we know what happened to the Y2K scare. – Jeff O Dec 3 at 2:54

The short answer is that you can't.

The long answer is that HTML is a context-free language, which is a way more powerful class of languages than regular languages, of which RegExp is an implementation. While I believe there are some small differences between the theory of regular expressions and its implementation in the industry, I doubt that it changes the expressive power of the tool enough to be able to parse a context-free language like HTML.

link|flag

I wouldn't. doing so is a Bad Thing™ and is bound to attract the demons of hell into this, our present dimension.

link|flag
@Muad'Dib, Bold statement from a little mouse – instanceofTom Dec 2 at 23:57
@instanceofTom Well, I AM "The One Who Points The Way" – Muad'Dib Dec 3 at 0:00
don't forget it will cause an unholy child to weep the blood of virgins – Conrad Frix Dec 3 at 0:49

The only possible way is to inject thue code into intercal to produce piet source code. Doing so creates a funge which, when traversed correctly, produces a proactive synergistic framework which can then be used to create the correct regex for parsing html.

link|flag

You could also cheat and use Perl 6 regular expressions. It's a misnomer because Perl 6 regexes are actually not regular expressions anymore. There's a readable regex recursion facility built in, so you can actually parse arbitrarily complex languages.

link|flag

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.