假设我在 Notepad++ 中打开了一个这样的文件:
[email protected]:word1
[email protected]:word2
[email protected]:word3
[email protected]:word4
[email protected]:word5
[email protected]:word6
[email protected]:word7
如您所见,第 1、2、3 行和第 6、7 行在“:”之前是重复的。是否有任何正则表达式可用于标记或删除“:”之前重复的所有行?
谢谢!
答案1
注意:这只对已排序的文件有效。
- Ctrl+H
- 找什么:
^([^:]+:).+\R(?:.*?\1.+(?:\R|$))+
- 用。。。来代替:
LEAVE EMPTY
- 检查环绕
- 检查正则表达式
- 取消选中
. matches newline
- Replace all
解释:
^ # beginning of line
([^:]+:) # group 1, 1 or more NOT colon followed by a colon (i.e. email address)
.+ # 1 or more any character but newline
\R # any kind of linebreak (ie. \r, \n, \r\n)
(?: # start non capture group
.*? # 0 or more any character, not greedy
\1 # backreference to group 1 (email address)
.+ # 1 or more any character but newline
(?:\R|$) # non capture group, a ine break or end of line
)+ # group may appear 1 or more times
给定示例的结果:
[email protected]:word4
[email protected]:word5