[英]Using Notepad++ find and replace with regular expression
I have a html menu file, which contains list of html pages, extracted by chm decoder. 我有一个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");
I want create from this a 'table of contents' file for Calibre (HTML file that contains links to all the other files in the desired order). 我希望从这个创建Caliber的“目录”文件(HTML文件包含所需顺序的所有其他文件的链接)。 The final file should look like this:
最终文件应如下所示:
<a href="final/pref04.html">Icons Used in This Book</a><br/>
<a href="final/pref05.html">Command Syntax Conventions</a><br/>
.
.
.
So first I need to remove the digit prefixes with regular expression, then add a href
attribute to make hyperlink, and change the URL and title position. 所以首先我需要用正则表达式删除数字前缀,然后添加
a href
属性来制作超链接,并更改URL和标题位置。 Can anyone show how to make this with Notepad++? 任何人都可以用Notepad ++展示如何制作这个吗?
I think this would do it for you, I'm mac based so I don't have notepad++ but this works in dreamweaver. 我想这会为你做,我是基于Mac的,所以我没有notepad ++但是这在Dreamweaver中有效。 Presuming each expression is one line based.
假设每个表达式都是基于一行的。
Find: 找:
\(.*?"(.*?)","(.*?)".*
Replace: 更换:
<a href="$2">$1</a><br/>
File: 文件:
(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");
After Replace All: 全部替换后:
<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/>
If it isn't one line based change .*
to .*?\\n
. 如果它不是一行改变
.*
到.*?\\n
。 That should make it stop after each newline. 这应该会在每个换行后停止。 For readability you also may want to add a newline to the replace.
为了便于阅读,您还可能需要为替换添加换行符。
Should probably explain the regex as well in case you want to modify it... 如果你想修改它,也应该解释正则表达式...
The first \\
is escaping the (
so the regex knows to look for the literal character and the not special regex grouping. The *?
says find every character until the first "
; ( .
is any single character, *
is zero or more occurrences of the preceding character, and ?
tells it to stop at the first occurrence of the next character, "
). The last .*
says keep going with the search. The (
and )
around the .*?
group the found value into the $1
and $2
. The number correlates to the order in which it is in the regex. 第一个
\\
正在逃避(
因此正则表达式知道要查找文字字符和非特殊的正则表达式分组。 *?
表示找到每个字符直到第一个"
;( .
是任何单个字符, *
是零或更多次出现的前面的字符,和?
告诉它在第一次出现下一个字符时停止, "
)。最后一个.*
表示继续搜索。 (
和)
围绕.*?
将找到的值分组到$1
和$2
该数字与正则表达式中的顺序相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.