我有一个包含如下内容的文本文件:
iosudhfsdkflasgj \aaa asdgsdga3453t.ggsdg\n \bbb
hjdfghjdfgjhh \ccc jtj56ywyrty546y \bbb
yjksfgh \aaa sefgwetgwgeregerg \bbb
u56j56jh \ddd agfwegaewrg\n \bbb
基本上,中间的字符串包含字母、数字,有时\n
在末尾,就在之前\bbb
。中间的字符串可以包含几个或很多字符。
我想删除以 开头\aaa
和以 结尾的字符串和,但保留中间部分。我也不想触及以、、开头的字符串...\bbb
\aaa
\bbb
\ccc
\ddd
\eee
结果应如下所示:
iosudhfsdkflasgj asdgsdga3453t.ggsdg\n
hjdfghjdfgjhh \ccc jtj56ywyrty546y \bbb
yjksfgh sefgwetgwgeregerg
u56j56jh \ddd agfwegaewrg\n \bbb
谢谢你!
答案1
- Ctrl+H
- 找什么:
\\aaa(\b.+?)\\bbb
- 用。。。来代替:
$1
- 检查环绕
- 检查正则表达式
- 取消选中
. matches newline
- Replace all
解释:
\\aaa # \aaa (the backslash has to be escaped)
(\b.+?) # group 1, a word boundry, 1 or more any character, not greedy
\\bbb # \bbb (the backslash has to be escaped)
给定示例的结果:
iosudhfsdkflasgj asdgsdga3453t.ggsdg\n
hjdfghjdfgjhh \ccc jtj56ywyrty546y \bbb
yjksfgh sefgwetgwgeregerg
u56j56jh \ddd agfwegaewrg\n \bbb