• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How can I parse this HTML with regex?

Woosta

Platinum Member
So, which one of you have not seen this epic answer on Stackoverflow?

http://stackoverflow.com/questions/1732348/1732454#1732454

Excerpt:

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&#8203;erves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Rege&#831;&#788;&#777;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&#865;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&#850;&#874;o&#859;&#875;rrupt entities (like SGML entities, but more corrupt) a mere glimpse of the world of reg&#8203;ex parsers for HTML will ins&#8203;tantly transport a programmer's consciousness into a world of ceaseless screaming, he comes, the pestilent slithy regex-infection wil&#8203;l devour your HT&#8203;ML parser, application and existence for all time like Visual Basic only worse he comes he comes do not fi&#8203;ght he com&#801;e&#822;s, &#789;h&#821;i&#8203;s un&#808;ho&#862;ly radian&#833;ce&#833; destro&#1161;ying all enli&#781;&#836;&#770;&#836;ghtenment, HTML tags lea&#864;ki&#807;n&#856;g fr&#822;o&#808;m &#801;yo&#8203;&#863;ur eye&#866;s&#824; &#795;l&#789;ik&#847;e liq&#8203;uid pain, the song of re&#824;gular exp&#8203;ression parsing will exti&#8203;nguish the voices of mor&#8203;tal man from the sp&#8203;here I can see it can you see &#818;&#858;&#790;&#852;&#793;i&#770;&#833;&#809;t&#769;&#779;&#832;&#818;&#846;&#809;&#817;&#852; it is beautiful t&#8203;he final snuffing of the lie&#8203;s of Man ALL IS LOS&#769;&#783;&#836;&#854;&#809;&#839;&#791;&#810;T ALL I&#8203;S LOST the pon&#823;y he comes he c&#822;&#814;omes he comes the ich&#8203;or permeates all MY FACE MY FACE &#7506;h god no NO NOO&#828;O&#8203;O N&#920; stop the an&#8203;*&#849;&#830;&#830;&#822;&#8203;&#773;&#875;&#847;&#793;&#804;g&#859;&#838;&#830;&#875;&#785;&#838;&#839;&#811;l&#781;&#875;&#869;&#872;&#854;&#841;&#791;&#809;&#819;&#799;e&#773;&#800;s &#846;a&#807;&#840;&#854;r&#829;&#830;&#836;&#850;&#849;e n&#8203;ot re&#768;&#785;&#871;&#780;a&#872;l&#771;&#868;&#834;&#830;&#774;&#792;&#797;&#793; ZA&#864;&#801;&#842;&#861;LG&#908; IS&#878;&#770;&#1161;&#815;&#840;&#853;&#825;&#792;&#817; TO&#837;&#839;&#825;&#826;&#413;&#820;&#563;&#819; TH&#792;E&#836;&#777;&#854; &#864;P&#815;&#845;&#813;O&#794;&#8203;N&#784;Y&#801; H&#872;&#842;&#829;&#773;&#830;&#782;&#801;&#824;&#810;&#815;E&#830;&#859;&#874;&#836;&#768;&#769;&#807;&#856;&#812;&#809; &#871;&#830;&#876;&#807;&#822;&#808;&#817;&#825;&#813;&#815;C&#877;&#783;&#869;&#878;&#863;&#823;&#793;&#818;&#797;&#854;O&#878;&#847;&#814;&#810;&#797;&#845;M&#842;&#786;&#794;&#874;&#873;&#876;&#794;&#860;&#818;&#790;E&#785;&#873;&#844;&#861;&#820;&#799;&#799;&#857;&#798;S&#879;&#831;&#788;&#808;&#832;&#805;&#837;&#811;&#846;&#813;
 
While I understand his point.... sometimes you just need to hack something together for a one-off job or something and I don't see the point in not using a regex in that case.
 
Haha, somewhere toward the end there an advanced virus or trojan appears to have entered his brain through the keyboard.
 
Back
Top