我想使用 Notepad++ 删除每行中重复的单词。
例子:
Flooring Services, Carpet, Flooring Services, Tile, Flooring Services
上文中,Flooring Services 重复了 3 次。我只想保留一 (1) 个 Flooring Services。
我查看了这个页面,它对于单个单词来说很好,但对于两个单词来说就不行: 如何使用 Notepad++ 删除每一行的所有重复的单词?
答案1
- Ctrl+H
- 找什么:
(?:^|,)\h*\K([^,\s]+(?:\h[^,\s]+)?),\h(?=.*\1)
- 用。。。来代替:
LEAVE EMPTY
- 打钩 相符
- 打钩 环绕
- 选择 正则表达式
- 取消勾选
. matches newline
- Replace all
解释:
(?:^|,) # non capture group, beginning of line OR comma
\h* # 0 or more horizontal spaces
\K # Reset operator, forget all we have seen until this position
( # group 1
[^,\s]+ # 1 or more any character that is not a comma or space
(?: # non capture group
\h # horizontal space
[^,\s]+ # 1 or more any character that is not a comma or space
)? # end group, optional
) # end group 1
,\h # a comma followed by a space
(?=.*\1) # positive lookahead, make sure we have the same word(s) somewhere after
截图(之前):
截图(之后):