EmEditor (text editor) Forum Index
   Regular Expressions
     how to delete duplicate lines
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Deipotent
Posted on: 8/10/2011 12:21 pm
Just can't stay away
Joined: 2/15/2008
From:
Posts: 118
Re: how to delete duplicate lines
I needed this functionality recently and thought it could be done easily with regex. Google led me to http://www.regular-expressions.info/duplicatelines.html which said to sort the lines, and then search for the following:

^(.*)(\r?\n\1)+$


and replace with:

\1


Unfortunately, I couldn't get this to work in EmEditor, even after enabling the option to search past line boundaries.

Can you add support for this type of regex to EmEditor ?

PS. I haven't tried the macro yet, and am sure it works fine, but it would be nice if it could be done with regex.
Yutaka
Posted on: 8/10/2011 1:11 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2398
Re: how to delete duplicate lines
In EmEditor \r is ignored, so you should try using this?

^(.*)(\n\1)+$


In future versions, I might add a new command to remove duplicate lines, so you won't need to use regular expression replace in the future.

Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

Deipotent
Posted on: 8/10/2011 3:50 pm
Just can't stay away
Joined: 2/15/2008
From:
Posts: 118
Re: how to delete duplicate lines
Thanks Yutaka, that did the trick!

A new command would be useful, particularly for people who don't scripting or RegEx, as a lot of other Text Editors include a simple menu option for removing duplicates. It would also allow you to highly optimise it, and also include an option to keep the original order (ie. so you don't have to sort it first), which would be useful.

One of my other suggestions was for a simple RegEx library feature, so you can create or import Regex's with a name, optional description, and possibly find settings. This would allow you to select the relevant regex from the library list and then run it.
Yutaka
Posted on: 8/10/2011 4:37 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2398
Re: how to delete duplicate lines
We are working on such those features in future versions.

Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

« 1 (2)
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文