notepad++正则表达式使⽤
版权声明:本⽂为博主⽪⽪blog.csdn/pipisorry原创⽂章,未经博主允许不得转载。
blog.csdn/pipisorry/article/details/21781111
notepad++正则表达式使⽤(持续更新中),删除、替换、查操作
正则表达式参考[]
CTRL+H 选择正则表达式
删除操作
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
⽪⽪Blog
替换操作
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:
—你看我是歌⼿吗? —不是。 为什么我的个⼦再也长不⾼了? 可能你得了恐⾼症
替换括号中匹配的内容\1\1
notepad++替换括号中匹配的内容
1.在的时候,是否经常碰到这样的语句需要翻译:
“Error adding the post!”;
“Error adding the comment!”;
“Error adding the user!”;
查⽬标:
“Error adding ([^!|"|;]*)
替换成:
“在增加\1时发⽣错误
结果是:
“在增加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
替换为:
=>\1\r\n
结果:
biscuits=>milk
yoghurt=>milk
tomato souce=>pasta
tomato souce=>milk
water pasta=>milk
正则表达式将数字开头替换为数字.开头
1.os.sep 可以取代
2.os.name
3os
查⽬标:
^(\d+)\.*
替换为:
\1.
结果:
1.os.sep 可以取代
2.os.name
3.os
Notepad++中在⼩数和字母间加上*号
查⽬标
(\d\.\d+)
替换为
\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'\)
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')
python正则表达式不包含
if c == b + 0.575*a :
print('True')
⽪⽪Blog
查操作
查括号中匹配的内容\1\1
notepad++查括号中匹配的内容
查出(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},不知道还有什么其他⽐较好的查⽅法?
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论