1

I want to remove duplicated words in each line using Notepad++.

Example:

Flooring Services, Carpet, Flooring Services, Tile, Flooring Services

In the above, Flooring Services is repeated 3x. I only want to keep one (1) Flooring Services.

I looked at this page which worked fine for a single word, but not for two words: How to remove all the duplicated words on every line using Notepad++?

Destroy666
  • 12,350

1 Answers1

2
  • Ctrl+H
  • Find what: (?:^|,)\h*\K([^,\s]+(?:\h[^,\s]+)?),\h(?=.*\1)
  • Replace with: LEAVE EMPTY
  • TICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Replace all

Explanation:

(?:^|,)         # 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

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Toto
  • 19,304