我有一个 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");
我想从中创建 Calibre 的“目录”文件(包含按所需顺序指向所有其他文件的链接的 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
。那应该使它在每个换行符之后停止。为了便于阅读,您可能还想在替换中添加换行符。
可能还应该解释正则表达式,以防您想修改它...
第一个 \
正在转义 (
因此正则表达式知道要查找文字字符和非特殊的正则表达式分组。*?
表示找到第一个 "
之前的每个字符;(.
是任何单个字符,*
是前面字符的零次或多次出现,并且?
告诉它在第一次出现下一个字符 "
时停止。最后一个 .*
表示继续搜索。 (
and )
围绕.*?
将找到的值分组为$1
和$2
。数字与其在正则表达式中的顺序相关。
关于html - 使用 Notepad++ 查找并替换为正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30386307/