我有一組HTML文件,其href
屬性的標籤中含有非法語法。例如,修復其中帶有雙引號的HTML屬性值
<a name="Conductor, "neutral""></a>
或
<meta name="keywords" content="Conductor, "hot",Conductor, "neutral",Hot wire,Neutral wire,Double insulation,Conductor, "ground",Ground fault,GFCI,Ground Fault Current Interrupter,Ground fault,GFCI,Ground Fault Current Interrupter,Arc fault circuit interrupter,Arc fault breaker,AFCI," />
或
<b>Table of Contents:</b><ul class="xoxo"><li><a href="1.html" title="Page 1: What are "series" and "parallel" circuits?">What are "series" and "parallel" circuits?</a>
我試圖處理與利用parsefile_html($file_name)
Perl的XML::Twig
模塊的文件。當讀取具有此語法的文件,它給這個錯誤:
x has an invalid attribute name 'y""' at C:/strawberry/perl/site/lib/XML/Twig.pm line 893
我需要的是兩種方式,以使模塊接受不良的語法和處理它,或正則表達式查找和替換帶有單引號的屬性中的雙引號。
偉大的作品!這是一個非常強烈的正則表達式。我會接受你的回答,但有些評論會對你有所幫助。 –
哎呀!對這個字符串沒有太大的作用:'' –
重複第二個替換(添加另一個替換) (?<= title =「)'。匹配試圖捕獲參數封閉的雙引號之間的所有內容,然後執行另一個替換以刪除它所找到的額外引號,然後用新引用替換舊引號。 – Kenosis