Remove duplicate lines without sorting

duplicatenotepadsorting

Is it possible to remove duplicated rows in Notepad++, leaving only a single occurrence of a line?

If I have these lines:
1
5
3
9

1
4
3

I want it to be:

1
5
3
9

4

I want it to keep first duplicated line, and remove all others duplicated lines… without sorting.

Could anyone help me please?

Best regards

Best Answer

The requirements are a Regex that:

  • Does not sort the lines (disqualifies TextFX).
  • Keeps the first occurrence and removes the later duplicates.

I'm also having this problem. So far I've got this: ^(.*?)$\s+?^(?=.*^\1$)

  • It only works in notepad++ if you enable the "." matches newline option.
  • It removes the first occurrence and keeps the later duplicates.

I use to have a great (but very slow) regex for this that was javascript, notepad++, and VisualStudio find-and-replace compatible, but I've lost it. If I can figure it out or find it again, I'll update this.

Related Question