繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM