广告
这是一则由第三方提供的广告,广告由自动化系统放置,广告的内容和链接与本站没有任何关联,如需帮助,请通过本站首页的邮箱进行联系。
此广告的地址:https://t.me/SinoPolitic
此广告价格:1.01 USD
广告到期时间: 2019-08-05 00:33:32
我要投放 关闭此信息

How to use RegEx to parse HTML

来自恶俗维基
跳到导航 跳到搜索

原标题

RegEx match open tags except XHTML self-contained tags

作者

bobince

削除前地址

https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

正文

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?

翻译(杂乱字符已消除)

你無法使用正則表達式解析[X]HTML。因為正則表達式無法解析HTML。正則表達式不是可用於正確解析HTML的工具。正如我之前在HTML以及正則表達式問題中回答過很多次,使用正則表達式不允許你使用HTML。正則表達式是一種不太複雜的工具,無法理解HTML所使用的構造。HTML不是正則語言,因此無法通過正則表達式進行解析。正則表達式查詢無法將HTML分解為有意義的部分。這麼多次,但它沒有找到我。即使是Perl使用的增強的不規則正則表達式也不能解析HTML。你永遠不會讓我破解。HTML是一種足夠複雜的語言,無法通過正則表達式進行解析。甚至Jon Skeet也無法使用正則表達式解析HTML。每當你試圖用正則表達式解析HTML時,邪惡的孩子就會為處女的鮮血哭泣,而俄羅斯黑客也會把你的webapp扯掉。用正則表達式解析HTML會將被污染的靈魂召喚到生活的領域。HTML和正則表達式就像愛情,婚姻和儀式殺嬰一樣。<center>無法忍受為時已晚。正則表達式和HTML一起在同一個概念空間中的力量會像骯髒的膩子一樣摧毀你的思想。如果你用正則表達式解析HTML,你就會屈服於他們以及他們褻瀆神靈的方式,這些方式使我們所有人都為不可描述的那個人付出了不人道的辛勞,他來了。當你看著他時,HTML以及正則表達式將會使感知者的神經液化,你的心靈在恐怖的衝擊中萎縮。基於正則表達式的HTML解析器是殺死StackOverflow的癌症已經太晚了太晚了我們無法保存孩子的傳言確保正則表達式會消耗所有活組織(除了HTML之外,如之前預言的那樣)親愛的主啊幫助我們如何使用正則表達式來解析HTML這個禍害已經註定人類永遠遭受恐懼折磨和安全漏洞使用正則表達式作為處理HTML的工具在這個世界與腐敗實體的恐懼領域之間建立了一個漏洞(如SGML實體,但更腐敗)只是一瞥HTML的正則表達式解析器世界將立即將程序員的意識傳遞到一個不斷尖叫的世界,他來了,瘟疫性的正則表達式感染將吞噬你的HTML解析器,應用程序和存在的所有時間就像Visual Basic一樣,更糟糕的是他來了,他來了不打他來,他邪惡的光芒摧毀了所有的靈性,HTML標籤從你的眼睛裡流出來像液體疼痛,這首歌正則表達式解析將熄滅整個地球凡人的聲音我可以看到它你能看到它是美麗的最後扼殺人類的謊言所有人都完了所有他完了他來的臥槽他來了他來了膿水滲透所有我臉上的面孔我的媽不臥槽停止天使不真實的恐怖是臥槽他來了


你就不會用XML解析器嗎?