[英]Using Notepad++ find and replace with regular expression
我有一個html菜單文件,其中包含由chm解碼器提取的html頁面列表。
(7,0,"Icons Used in This Book","final/pref04.html");
(8,0,"Command Syntax Conventions","final/pref05.html");
(9,0,"Introduction","final/pref06.html");
(10,0,"Part I: Introduction and Overview of Service","final/part01.html");
(11,10,"Chapter 1. Overview","final/ch01.html");
(12,11,"Technology Motivation","final/ch01lev1sec1.html");
我希望從這個創建Caliber的“目錄”文件(HTML文件包含所需順序的所有其他文件的鏈接)。 最終文件應如下所示:
<a href="final/pref04.html">Icons Used in This Book</a><br/>
<a href="final/pref05.html">Command Syntax Conventions</a><br/>
.
.
.
所以首先我需要用正則表達式刪除數字前綴,然后添加a href
屬性來制作超鏈接,並更改URL和標題位置。 任何人都可以用Notepad ++展示如何制作這個嗎?
我想這會為你做,我是基於Mac的,所以我沒有notepad ++但是這在Dreamweaver中有效。 假設每個表達式都是基於一行的。
找:
\(.*?"(.*?)","(.*?)".*
更換:
<a href="$2">$1</a><br/>
文件:
(7,0,"Icons Used in This Book","final/pref04.html");
(8,0,"Command Syntax Conventions","final/pref05.html");
(9,0,"Introduction","final/pref06.html");
(10,0,"Part I: Introduction and Overview of Service","final/part01.html");
(11,10,"Chapter 1. Overview","final/ch01.html");
(12,11,"Technology Motivation","final/ch01lev1sec1.html");
全部替換后:
<a href="final/pref04.html">Icons Used in This Book</a><br/>
<a href="final/pref05.html">Command Syntax Conventions</a><br/>
<a href="final/pref06.html">Introduction</a><br/>
<a href="final/part01.html">Part I: Introduction and Overview of Service</a><br/>
<a href="final/ch01.html">Chapter 1. Overview</a><br/>
<a href="final/ch01lev1sec1.html">Technology Motivation</a><br/>
如果它不是一行改變.*
到.*?\\n
。 這應該會在每個換行后停止。 為了便於閱讀,您還可能需要為替換添加換行符。
如果你想修改它,也應該解釋正則表達式...
第一個\\
正在逃避(
因此正則表達式知道要查找文字字符和非特殊的正則表達式分組。 *?
表示找到每個字符直到第一個"
;( .
是任何單個字符, *
是零或更多次出現的前面的字符,和?
告訴它在第一次出現下一個字符時停止, "
)。最后一個.*
表示繼續搜索。 (
和)
圍繞.*?
將找到的值分組到$1
和$2
該數字與正則表達式中的順序相關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.