想在notepad ++中用正则表达式替换

时间:2013-11-07 11:18:51

标签: regex notepad++

我有一个内容类似于以下内容的文本文件。我想使用Notepad ++的查找和替换功能删除Bank Applicants(数字字符串)之间的所有文本。

0004829 01-02 000421
0004830 01-02 000422
0466608 06-47 000743
Bank sl. no beginning with an 'IA' indicates ICB account
Paramount Textile Limited Page No: 143 of 258
Lottery Conducted by--Dept. of Electrical and Electronic Engineering, BUET. Date:03/10/2013
General
Applicants
0004823 01-02 000415
0004824 01-02 000416
0004826 01-02 000418
0004829 01-02 000421
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
Bank sl. no beginning with a
Lottery Conducted by--Dept. of Electrical and Electronic Engineering, BUET. Date:03/10/2013
General
Applicants
0004823 01-02 000415
0004829 01-02 000421
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
0004839 01-02 000431
0004840 01-02 000432
Bank sl. no beginning with an 'IA' indicates ICB account
and Electronic Engineering, BUET. Date:03/10/2013
General
Applicants
0004823 01-02 000415
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
0004839 01-02 000431

我想要的输出示例如下:

0004829 01-02 000421
0004830 01-02 000422
0466608 06-47 000743
0004823 01-02 000415
0004824 01-02 000416
0004826 01-02 000418
0004829 01-02 000421
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
0004823 01-02 000415
0004829 01-02 000421
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
0004839 01-02 000431
0004840 01-02 000432
0004823 01-02 000415
0004830 01-02 000422
0004831 01-02 000423
0004832 01-02 000424
0004839 01-02 000431

5 个答案:

答案 0 :(得分:3)

将notepad ++搜索和替换置于正则表达式模式并搜索^[^0-9].*\r\n替换为你应该留空

确保。与新行不匹配设置和输出enter image description here

下面的图片

答案 1 :(得分:1)

而不是查找转到标记标签。找到所有匹配“^ 000”的行,启用“书签行”选项,然后单击“全部标记”。所有与“0004829 01-02 000421”相似的行都会被加入书签。

现在删除所有剩余的行:搜索>书签>删除未标记的行。

编辑:而不是“^ 000”更好地使用“^ [0-9] {3}”。

答案 2 :(得分:1)

正则表达式可以找到除您的银行帐号以外的任何内容:

^((?!\d{7}\s\d{2}-\d{2}\s\d{6}).)*$

这会搜索除7位数字后面的空格,然后是2位数后跟一个连字符,然后搜索其他2位数字和另一个空格以及6位最终数字。

您可以使用它来标记与此模式匹配的所有行,然后删除标记行。

答案 3 :(得分:0)

使用vim,正则表达式将是:

g/^Bank/,/^Applicants/d

答案 4 :(得分:0)

尝试使用:

找到:Bank.+?Applicants\r?\n
替换为:<nothing>

然后点击Replace all

确保您已选中Regular expressiondot matches newline