Regex: Remove any duplicates within a line, irrespective of length, with 10 characters.

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Dustydog
Posts: 321
Joined: 13 Jun 2016 04:19

Regex: Remove any duplicates within a line, irrespective of length, with 10 characters.

Post by Dustydog »

(.+)\1 > $1

I accidentally, in another app, renamed some files with: 01. The File Name That Looked Like This The File Name That Looked Like This.flac

That regular expression will rename the whole thing to: 01. The File Name That Looked Like This.flac - in 10 characters. It took more time to mess it up than to fix it.

It's quite powerful and will delete duplicate anythings, from phrases to double letters, so be careful. For example "too too much too too much stuff" will come out "too too much stuf" so you do have to be careful unless you refine it or really know what you're doing.

It's just an example of the power of regular expressions - they'll make XY much more useful if you learn them to at least some degree. A major use is shuffling around parts of a matching phrase.

Explaining just what that does is beyond the scope of this little post, but (among many) https://www.rexegg.com/ or https://www.regular-expressions.info/tutorial.html will give a good grounding and then some. The last is Jan Goyvaerts' site - he makes many tools and is an all-around regular expression God.

*Adding a word boundary makes it a little more reliable - but it takes two more characters (.+)\b\1 > $1 :biggrin:

Post Reply