aholtz
aholtz

Reputation: 25

Remove duplicated strings within Notepad++

I was trying to find a way to remove duplicated strings within Notepad++ (not removing duplicated lines). For example, if I have the text:

Alice's favorite ice cream (not gelato) is: Vanilla! Alice's favorite ice cream (not gelato) is: Vanilla! Please go get some ice cream from the store

The result should be

Alice's favorite ice cream (not gelato) is: Vanilla! Please go get some ice cream from the store

I tried looking up some examples and found this but it doesn't really work exactly as expected. Thanks in advance.

Upvotes: 2

Views: 4517

Answers (2)

Hagbard
Hagbard

Reputation: 3700

I just had a similar problem and wanted to remove duplicate lines. It turns out that there is already a built-in feature to do that.

Just go to "Edit->Line Operations->Remove Consecutive Duplicate Lines".

Upvotes: 1

Federico Piazza
Federico Piazza

Reputation: 31035

If you have consecutive duplicates then you can use a regex like this:

(.*)\1

Working demo

And use the replacemente string: \1 or $1 as you can see in the substitution section in the screenshot.

enter image description here

Update: as 1010 pointed in this comment:

beware that it may match duplicates like the 'o' in "look", or parts of a sentence that repeats characters as in "... this is a duplicate"

You can prevent this by creating a limitation for minimal duplicated chars. For instance, this regex looks for duplicated chars that will have at least 5 duplicated characters (you can modify the numbere for what you consider right):

(.{5,})\1

Upvotes: 2

Related Questions