html - 使用 Notepad++ 查找并替换为正则表达式

标签 html regex notepad++ calibre

我有一个 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/

相关文章:

javascript - 为什么我无法在 Google Chrome 中返回 cookie?

javascript - 使用事件处理程序创建 javascript 对象

javascript - 如何在 HTML5 中转换 -90 度后使网页适合?

python - 如何使用带有选项(如或条件)的 TextFSM 解析文本

javascript - Notepad++ 无法打开我的 html 文件,而是打开 google 主页

php - Notepad++ 为 PHP 编辑语法突出显示?

Javascript - 在 div 中创建一系列 <a> 标签

python - 在mysql加载数据文件导入期间删除CSV公式值

regex - 如何从 logstash 中删除事件?

正则表达式匹配换行符-为什么?