是否有可能在notepad++中删除重复的行,只留下一行的单一出现?


当前回答

扩展顶部的答案,还可以使用第二个前向查找几乎与其他行重复的行。

^(±s * (< PackageReference包括=”。* * *版=)。*)$±s +?^(?=.*^\ 2 . *美元)

这里我在多次引用同一个<PackageReference Include="。字符串,不管它的版本。

测试数据

<PackageReference Include="Package1" Version="2.2.1" />

    <PackageReference Include="Package1" Version="2.2.1" /> // Match
<PackageReference Include="Package1" Version="2.2.2" />

<PackageReference Include="Package2" Version="5.1" /> // Match
<PackageReference Include="Package2" Version="5.2" />

<PackageReference Include="Package3" Version="2.2.1" /> // No match
<PackageReference Include="Package4" Version="2.2.1" />

查看regex术语含义的详细说明,并尝试使用这个regex101共享中的您自己的数据。

其他回答

从notepad++版本6开始,你可以在搜索和替换对话框中使用这个正则表达式:

^(.*?)$\s+?^(?=.*^\1$)

什么都不替换。这将在所有重复行中留下文件中最后一次出现的内容。

不需要排序,重复的行可以在文件中的任何地方!

您需要勾选“正则表达式”和“正则表达式”选项。匹配换行符”:

^ matches the start of the line. (.*?) matches any characters 0 or more times, but as few as possible (It matches exactly on row, this is needed because of the ". matches newline" option). The matched row is stored, because of the brackets around and accessible using \1 $ matches the end of the line. \s+?^ this part matches all whitespace characters (newlines!) till the start of the next row ==> This removes the newlines after the matched row, so that no empty row is there after the replacement. (?=.*^\1$) this is a positive lookahead assertion. This is the important part in this regex, a row is only matched (and removed), when there is exactly the same row following somewhere else in the file.

在NPP很难做到这一点。 更好的方法是:

下载cygwin实用程序,这是一个简单的Linux终端在windows下。 它允许在Windows中执行任何Linux命令。 这里是排序-u。

Notepad + +

->替换window

确保在搜索模式中选择了正则表达式单选按钮

找到:

(*) ^ (r ? (n - 1) +美元

替换为:

$1

之前:

我们认为 我们认为 一行 有可能 有可能

后:

我们认为 一行 有可能

你可能需要一个插件来做到这一点。您可以尝试ConyEdit的命令行cc.ddl(删除重复的行)。它是一个文本编辑器的跨编辑器插件,包括notepad++。

使用ConyEdit在后台运行,遵循以下步骤:

在文本末尾输入命令行cc.ddl。 复制文本和命令行。 粘贴,然后你会看到你想要的。

例子

无论文件是否排序,您都可以使用下面的regex删除文件中任何位置的重复项。

^([^\r]*[^\n])(.*?)\r?\ n \ 1美元 替换为:\1\2 搜索模式:

“正则表达式” 检查“。匹配换行"选项

尽可能多地点击“替换全部”(或按住Alt+A快捷键),直到你看到“0次发生被替换”