2013-03-02 59 views
0

我有一張表,其中包含數百個帶有屏幕截圖的指南。截圖圖像被錨點標記包圍,因爲它們之前可以點擊,但現在我需要刪除錨點標記。所有要刪除的定位標記都有一個href=#screenshot,後面跟着一個數字,如下例所示。我的計劃是使用mysqldump轉儲表,然後使用sed查找並替換正確的字符串。使用SED在數據庫中的html中刪除特定的錨標記

<p>Choose <a href="/components">components</a> to install and click next.</p> 
<div class="screen"> 
<a href="#screenshot3"><img src="/images/screens/install/step3.jpg" alt="Step 3"></a> 
</div> 

應該

<p>Choose <a href="/components">components</a> to install and click next.</p> 
<div class="screen"> 
<img src="/images/screens/install/step3.jpg" alt="Step 3"> 
</div> 

我可以使用<a\shref\=\"#screenshot\d+\"\>第一標籤匹配,但我也需要這樣既可以同時不刪除其他錨標記被刪除其第二關閉標籤相匹配。任何幫助將不勝感激!

回答

1

你可以嘗試用\1更換

<a\shref\=\"#screenshot\d+\"\>(.*)<\/a> 

括號將捕獲在兩者之間找到一切,讓您可以使用\1\2 ...

請記住儘管這正則表達式是不是要修改HTML時要使用合適的武器恢復。請閱讀this(及其附帶的註釋)以獲得解釋。