【问题标题】:Using Notepad++ find and replace with regular expression使用 Notepad++ 查找和替换正则表达式
【发布时间】:2015-05-21 23:57:21
【问题描述】:

我有一个 html 菜单文件,其中包含 html 页面列表,由 chm 解码器提取。

(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++ 制作这个吗?

【问题讨论】:

    标签: html regex notepad++ calibre


    【解决方案1】:

    我认为这会为你做这件事,我是基于 mac 的,所以我没有记事本++,但这在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。该数字与它在正则表达式中的顺序相关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2015-01-11
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多