notepad++ 正则表达式 高级查找替换技巧(一)

正则表达式:(^\w+$)

替换式:db2 \"delete from \1 \" \r\ndb2 \"import from \.\/data\/\1\.ixf of ixf modified by identityignore insert into \1 \"

输入:

PERMODLOG

RESERVEDETAIL

RESERVEMAIN

输出:

db2 "delete from PERMODLOG "

db2 "import from ./data/PERMODLOG.ixf of ixf modified by identityignore insert into PERMODLOG "

db2 "delete from RESERVEDETAIL "

db2 "import from ./data/RESERVEDETAIL.ixf of ixf modified by identityignore insert into RESERVEDETAIL "

db2 "delete from RESERVEMAIN "

db2 "import from ./data/RESERVEMAIN.ixf of ixf modified by identityignore insert into RESERVEMAIN "

 

 

 

正则表达式:(^\w+$)

替换式:db2 \"export to \.\/data\/\1\.ixf of ixf select \* from \1 \"

输入:

PERMODLOG

RESERVEDETAIL

RESERVEMAIN

输出:

db2 "export to ./data/PERMODLOG.ixf of ixf select * from PERMODLOG "

db2 "export to ./data/RESERVEDETAIL.ixf of ixf select * from RESERVEDETAIL "

db2 "export to ./data/RESERVEMAIN.ixf of ixf select * from RESERVEMAIN "

 

正则表达式:(alter.*\))

替换式:execute immediate '\1'

输入:

alter table MonQryApply add constraint PK_MonQryApply primary key (orderID);

alter table sRegInfo add constraint PK_sRegInfo primary key (MachID);

输出:

execute immediate 'alter table MonQryApply add constraint PK_MonQryApply primary key (orderID)';

execute immediate 'alter table sRegInfo add constraint PK_sRegInfo primary key (MachID)';

 

正则表达式:ASC\)\s*tablespace GZHINDEX\s*pctfree 10\s*initrans 2\s*maxtrans 255\s*storage\s*\(\s*initial 64K\s*next 1M\s*minextents 1\s*maxextents unlimited\s*\);

替换式:ASC\);

作用:去掉以下sql中的ASC)后面的内容。

CREATE INDEX IX_BANKCHECKDAILYREP_CHECKDATE

ON BANKCHECKDAILYREP (CHECKDATE ASC)

tablespace GZHINDEX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

 

-- ----------------------------

-- Indexes structure for table BANKCHECKDAILYREP_LIST

-- ----------------------------

CREATE INDEX IX_BANKCHECKLIST_CHECKDATE

ON BANKCHECKDAILYREP_LIST (CHECKDATE ASC)

tablespace GZHINDEX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

 

正则表达式:^select \*(.+)$

替换式:delete \1 ;

作用:把select * 替换成delete , 同时在行尾加分号

 

正则表达式:^INSERT INTO

替换式:go\r\nINSERT INTO

作用:每一行的前面增加一个新行,内容为go

 

正则表达式:^(\w+.+)$

替换式:\1\r\ngo

作用:每隔一行增加一个新行,内容为go

 

正则表达式:^(--.*)$

替换式:空

作用:去掉以“--”开始的注释

 

 

 

 

 

扩展模式替换

查找目标:);

替换: ASC)\r\n tablespace GZHINDEX\r\n pctfree 10\r\n initrans 2\r\n maxtrans 255\r\n storage\r\n (\r\n initial 64K\r\n next 1M\r\n minextents 1\r\n maxextents unlimited\r\n );\r\n

输入:

create index IX_BUSINESSLIST_ATM_ACCOUNTNO on BUSINESSLIST_ATM (ACCOUNTNO);

create index IX_BUSINESSLIST_ATM_COREID on BUSINESSLIST_ATM (COREID);

create index IX_BUSINESSLIST_ATM_INSERDATE on BUSINESSLIST_ATM (INSERTDATE);

输出:

create index IX_BUSINESSLIST_ATM_ACCOUNTNO on BUSINESSLIST_ATM (ACCOUNTNO ASC)

tablespace GZHINDEX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

 

create index IX_BUSINESSLIST_ATM_COREID on BUSINESSLIST_ATM (COREID ASC)

tablespace GZHINDEX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

 

create index IX_BUSINESSLIST_ATM_INSERDATE on BUSINESSLIST_ATM (INSERTDATE ASC)

tablespace GZHINDEX

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

 

 

给冠字号两侧加单引号

输入:

WFD545

FDS654A

FDS7887

正则表达式

^(\w+)$

'\1',

输出:

'WFD545',

'FDS654A',

'FDS7887',

 

 

(nvl\(.*),\s*''\)\s*=\s*''

\1, 'N'\)='N'

 

输入:

nvl(:new.pertype,'')<>nvl(:old.pertype,'')

select nvl(cashid,'') into v_cashid from

正则表达式:

(nvl\(\s*[:.\w]*\s*),\s*''\s*\)

\1, 'N'\)

输出:

nvl(:new.pertype,'N')<>nvl(:old.pertype,'N')

select nvl(cashid,'N') into v_cashid from

 

/truncate table (\w+)/

/alter table \1 activate not logged initially with empty table;/

 

 

 

输入:

alter table T_BILL_TOTAL_H modify BAGNAME varchar2(80);

alter table T_BILL_TOTAL_H modify CHECKNAME varchar2(80);

 

alter table T_BILL_TOTAL_NET modify BAGNAME varchar2(80);

alter table T_BILL_TOTAL_NET modify CHECKNAME varchar2(80);

 

alter table T_EX_RETURN modify BAGNAME varchar2(80);

alter table T_EX_RETURN modify CHECKNAME varchar2(80);

 

alter table T_EX_RETURNBUNDLE modify BAGNAME varchar2(80);

alter table T_EX_RETURNBUNDLE modify CHECKNAME varchar2(80);

 

alter table t_bankandnet modify bankname varchar2(120);

alter table t_bankandnet modify shortname varchar2(120);

 

正则表达式(/是用来标识开头和结尾的)

/modify (\s*\w+\s*) varchar2\(/

/alter \1 set data type varchar\(/

输出:

alter table T_BILL_TOTAL_H alter BAGNAME set data type varchar(80);

alter table T_BILL_TOTAL_H alter CHECKNAME set data type varchar(80);

 

alter table T_BILL_TOTAL_NET alter BAGNAME set data type varchar(80);

alter table T_BILL_TOTAL_NET alter CHECKNAME set data type varchar(80);

 

alter table T_EX_RETURN alter BAGNAME set data type varchar(80);

alter table T_EX_RETURN alter CHECKNAME set data type varchar(80);

 

alter table T_EX_RETURNBUNDLE alter BAGNAME set data type varchar(80);

alter table T_EX_RETURNBUNDLE alter CHECKNAME set data type varchar(80);

 

alter table t_bankandnet alter bankname set data type varchar(120);

alter table t_bankandnet alter shortname set data type varchar(120);

 

正则表达式(/是用来标识开头和结尾的)

/([\s,\(]*)now\(\s*\)([\s,\)]*)/

/\1current timestamp\2/

 

正则表达式(/是用来标识开头和结尾的)

/ int([\s;]+)/

/ integer\1/

 

查找实例(正则表达式):

create.*function.*CURRNAME

 

 

在正则表达式中,括号( 是特殊符号,如果要匹配字符'(' 或 ')', 则需要加转义符\。

如 '\(' 和 '\)'

匹配一整行

^ KEY (.*)$

^DROP TABLE IF EXISTS (.*)$

 

 

查找目标: ^\) ENGINE=MYISAM AUTO_INCREMENT(.*)$

替换为: \)IN "USERSPACE1" ;

替换为的字符串中如果有括号,如")IN "USERSPACE1" ; "则要加转义符'\',否则会被转换成空行。

 

 

 

 

 

 

CREATE TABLE BAGINFO(

BAGCODE VARCHAR2(20 BYTE) NOT NULL ,

BANKID VARCHAR2(20 BYTE) NULL ,

BAGDATE DATE NULL ,

BAGBAGID VARCHAR2(20 BYTE) NULL ,

BAGCHECKID VARCHAR2(20 BYTE) NULL ,

BUNDLECODE VARCHAR2(30 BYTE) NULL ,

BUNDLEDATE DATE NULL ,

INSERTDATE DATE NULL ,

WRITESTATUS CHAR(1 BYTE) NULL ,

FILENAME VARCHAR2(60 BYTE) NULL ,

PUTSTATUS CHAR(1 BYTE) DEFAULT 1 NULL

)

 

 

;

 

替换后就去掉了)号和;号之间的空行

 

比如一行中有以下字符: 12q34m56 用下面的正则就可以匹配到 ^(.*)34(.*)$

 

匹配空行用下面的几个正则,其中一个一定是可用的.如果无效.可以重启下notepad++

^(\s*)\r\n ^(.*)\(\n\) ^(\s*)\r\n

 

 

匹配不定个数空白行,并删除

^(\s*)\r\n\)IN "USERSPACE1" ;

\)IN "USERSPACE1" ;

 

 

删除多余的逗号

,\r\n\)IN "USERSPACE1" ;

\r\n\)IN "USERSPACE1" ;

 

 

去掉不定长的一列(还可勾选匹配大小写)

INSERT INTO T_RoleModules VALUES (.*)R00

INSERT INTO T_RoleModules VALUES \('R00

 

 

 

删除操作

notepad++去掉行尾空格或逗号

查找目标:\s+$ (或,+$)

替换为空

Note: 以换行符结尾表示是$\r\n,而不是\r\n$

notepad++删除文本文件里面的空白行

查找目标:^[ \t]*\n或者:^\r\n

替换为空

notepad++去掉只有数字的行

查找目标:^[\d]+$\r\n

替换为空

notepad++去掉不是以某个数开头的行

查找目标:^[^1].*\r\n

替换为空

 

notepad++去掉所有行中的<>(里面不能嵌套<>)

查找目标:<[^>]*>

替换为空

input:

<code><span class="kwd">import</span><span class="pln"> </span><dfn><span class="typ">BaseHTTPServer</span></dfn><span class="pln">

</span><span class="kwd">import</span><span class="pln"> </span><dfn><span class="typ">SimpleHTTPServer</span></dfn><span class="pln">

</span><span class="kwd">import</span><span class="pln"> </span><dfn><span class="typ">CGIHttpServer</span></dfn></code>

output:

import BaseHTTPServer

import SimpleHTTPServer

import CGIHttpServer

 

notepad++去掉python代码中的注释

去掉''' '''之间的注释

查找目标(regular expression)

^.*?'''\r\n.*?\r\n.*?'''\r\n

替换为空

去掉#注释

查找目标(re)

^(.*?)#.*?\r\n

替换为

\1\r\n

再去掉空行

如果只去掉注释行而不删除代码后面跟着的#注释则查找目标为

^\s+#.*?\r\n

 

 

替换操作

notepad++替换所有行中的(Week 1)  \n II. 为 ;

查找目标:\([^\.]*\.

替换为空

input:

I. Introduction机器学习综述 (Week 1)

 

II. Linear Regression with One Variable单变量线性回归 (Week 1)

 

III. Linear Algebra Review线性代数 (Week 1, Optional)

output:

I. Introduction机器学习综述 ;Linear Regression with One Variable单变量线性回归 ;Linear Algebra Review线性代数

Note:(和.都是特殊字符,要转义;\(代表从字符(开始; [^\.]*代表非字符.的字符重复n次; \.表示到字符.为止

notepad++将[]及包含的字母替换成空

查找目标

[/]∗[[:alpha:]]∗ 

替换为空

input:

[cp] —你看我是歌手吗? —不是。[/cp] [cp] 为什么我的个子再也长不高了? 可能你得了恐高症[/cp] [cp]

output:

—你看我是歌手吗? —不是。  为什么我的个子再也长不高了? 可能你得了恐高症  

 

 

notepad++替换括号中匹配的内容\1

1.在汉化的时候,是否经常碰到这样的语句需要翻译:

“Error adding the post!”; 

“Error adding the comment!”; 

“Error adding the user!”;

查找目标:

“Error adding ([^!|"|;]*)

Error adding the ([^!|”|;]*) //wlj method

替换成:

“在增加\1时发生错误

在增加\1时发生错误 //wlj method

结果是:

“在增加the post时发生错误!”; 

“在增加the comment时发生错误!”; 

“在增加the user时发生错误!”;

Note:

1. ([^!|"|;]*) 的意思是 不等于 ! 和 ” 和 ; 中的任何一个,意思就是这3个字符之外的所有字符将被选中(替换区域);

2. 正则表达式中\1表示第一个括号里面匹配内容。

 

正则表达式将倒数第一个\t替换为=>

biscuits milk

yoghurt milk

tomato souce pasta

tomato souce milk

water pasta milk

查找目标:(RE)

\t(\w+?)\r\n

\s+(\w+)$ //wlj method

替换为:

=>\1\r\n

=>\1 //wlj method

结果:

biscuits=>milk

yoghurt=>milk

tomato souce=>pasta

tomato souce=>milk

water pasta=>milk

正则表达式将数字开头替换为数字.开头

1.os.sep    可以取代

2.os.name

3os

4aaa

aaaaaaaa

查找目标:

^(\d+)\.*

替换为:

\1.

结果:

1.os.sep    可以取代

2.os.name

3.os

4.aaa

aaaaaaaa

 

Notepad++中在小数和字母间加上*号

查找目标

(\d\.\d+)

(\d+\.*\d*) //wlj method

替换为

\1\*

input:

0.95c == 0.9b + 0.475a

c == 0.9b + 0.475a

0.85a == c + 0.15b

c == b + 0.575a

output:

0.95*c == 0.9*b + 0.475*a

c == 0.9*b + 0.475*a

0.85*a == c + 0.15*b

c == b + 0.575*a

 

Notepad++中在字符串上加上引号

查找目标

(\w+)

替换为

'\1'

input:

c, i, nd, o, p, u

output:

'c', 'i', 'nd', 'o', 'p', 'u'

 

Notepad++将每行赋值语句修改成判断语句

查找目标

^(.*)$

替换为

if  \1 :\n\tprint ′ True ′  

if \1 then\r\n print 'true' //wlj method

input:

0.95*c == 0.9*b + 0.475*a

c == 0.9*b + 0.475*a

0.85*a == c + 0.15*b

c == b + 0.575*a

output:

if  0.95*c == 0.9*b + 0.475*a :

    print('True')

if  c == 0.9*b + 0.475*a :

    print('True')

if  0.85*a == c + 0.15*b :

    print('True')

if  c == b + 0.575*a :

    print('True')

皮皮Blog

 

 

查找操作

notepad++查找括号中匹配的内容\1

查找出(0 0 1)(0 1 1)T, x③=(-1 0 -1)T, x④=(-1 -1 -1)中小括号内的内容

查找目标:

.*?((−∗\d\s∗)+  ).*?

替换成:

\1

结果是:

(0 0 1)(0 1 1)(-1 0 -1)(-1 -1 -1)

Note: 这个查找效果不是很好,达不到用python编写re.findall()的效果。

notepad++查找括号()中的内容\1

查找出

        ω1:{(1 0)T, (2 0) T, (1 1) T}

        ω2:{(-1 0)T, (0 1) T, (-1 1) T}

        ω3:{(-1 -1)T, (0 -1) T, (0 -2) T}

中小括号内的内容

查找目标:

.*?(\-∗\d\s\-∗\d  ).*?

替换成:

\1

结果是:

(1 0)(2 0)(1 1) T}

(-1 0)(0 1)(-1 1) T}

(-1 -1)(0 -1)(0 -2) T}

还要自己删除后面多余的T},不知道还有什么其他比较好的查找方法?

 

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值