# Merge duplicate words

**URL:** https://community.mp3tag.de/t/merge-duplicate-words/16289
**Category:** Support
**Created:** [November 3, 2014, 9:33am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289 "2014-11-03T09:33:02Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![ForSSound](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/258eb7/32.png) [@ForSSound](https://community.mp3tag.de/u/ForSSound)
#### Post date: [November 3, 2014, 9:33am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/1 "2014-11-03T09:33:02Z")

</div>

Hi,

I would like to find in genre duplicate words and merge them together.

This is an example of genre tag:

Before

```
AFRICA; AFRICA; NATURAL WORLD; NATURE STUDY; NATURE; DRAMA ADVENTURE; DRAMA WORLD; PERCUSSION; INSTRUMENTS SOLO PERCUSSION; WILDLIFE MOVEMENT; DRAMA ADVENTURE; AFRICA; FILM STYLES ANCIENT ROME; AFRICA

```

After

```
AFRICA; NATURAL WORLD; NATURE STUDY; NATURE; DRAMA WORLD; PERCUSSION; INSTRUMENTS SOLO PERCUSSION; WILDLIFE MOVEMENT; DRAMA ADVENTURE; FILM STYLES ANCIENT ROME

```

; is the separator here  
[A-Z]\*; I think will match every entry for this songs genre

AFRICA is for instance 4 times repeated and I would like to merge them into 1 time  
DRAMA ADVENTURE is twice repeated

Is there a way to do this?

Kind regards  
Guy Forssman

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [November 3, 2014, 3:21pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/2 "2014-11-03T15:21:16Z")

</div>

> [@ForSSOund](#):
>
> ... I would like to find in genre duplicate words and merge them together. ...

Search there ...  
[https://www.google.de/search?q=site%3Aforum...p;oq=&gs\_l=](https://www.google.de/search?q=site%3Aforums.mp3tag.de+Removing+Duplicate&gws_rd=ssl&oq=&gs_l=)

Read there ...  
[Doppelte Genre löschen](https://community.mp3tag.de/t/14319/10)

DD.20141103.1721.CET

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [November 3, 2014, 4:11pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/3 "2014-11-03T16:11:46Z")

</div>

> [@ForSSOund](#):
>
> Hi,
> 
> I would like to find in genre duplicate words and merge them together.
> 
> This is an example of genre tag:
> 
> Before
> 
> ```
> AFRICA; AFRICA; NATURAL WORLD; NATURE STUDY; NATURE; DRAMA ADVENTURE; DRAMA WORLD; PERCUSSION; INSTRUMENTS SOLO PERCUSSION; WILDLIFE MOVEMENT; DRAMA ADVENTURE; AFRICA; FILM STYLES ANCIENT ROME; AFRICA
> 
> ```
> 
> After
> 
> ```
> AFRICA; NATURAL WORLD; NATURE STUDY; NATURE; DRAMA WORLD; PERCUSSION; INSTRUMENTS SOLO PERCUSSION; WILDLIFE MOVEMENT; DRAMA ADVENTURE; FILM STYLES ANCIENT ROME
> 
> ```
> 
> Kind regards  
> Guy Forssman

You want to keep the first value. That's more complicated.

[Edit:]  
Action: Format value  
Field: Genre  
Format string: `$regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;*|\s*;+)+|(\s+;*|\s*;+)+$|((?<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;.*?\1))',),'^;+|;+$',)),'(?<=;)',' ')`

Replace Genre with any other tag and it will remove duplicates too.  
This action "fixes" first the multiple value string (remove multiple spaces after ; separator).  
It will add exactly one space after value separator [;].

Enjoy. 😉

---

<div class="post-metadata">

### Author: ![ForSSound](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/258eb7/32.png) [@ForSSound](https://community.mp3tag.de/u/ForSSound)
#### Post date: [November 4, 2014, 6:20am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/4 "2014-11-04T06:20:30Z")

</div>

> [@DetlevD](#):
>
> Search there ...  
> [https://www.google.de/search?q=site%3Aforum...p;oq=&gs\_l=](https://www.google.de/search?q=site%3Aforums.mp3tag.de+Removing+Duplicate&gws_rd=ssl&oq=&gs_l=)
> 
> Read there ...  
> [Doppelte Genre löschen](https://community.mp3tag.de/t/14319/10)
> 
> DD.20141103.1721.CET

Hi I apreciate your answer as yesterday I couldn't search ...  
Your type of answer will motivate me to search in the next time even better, if I can find it I'm helped immediately 🙂

Thank you for your patience with me  
Guy Forssman

---

<div class="post-metadata">

### Author: ![ForSSound](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/258eb7/32.png) [@ForSSound](https://community.mp3tag.de/u/ForSSound)
#### Post date: [November 4, 2014, 6:26am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/5 "2014-11-04T06:26:02Z")

</div>

> [@Victor Kostas](#):
>
> You want to keep the first value. That's more complicated.
> 
> [Edit:]  
> Action: Format value  
> Field: Genre  
> Format string: $regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;_|\s_;+)+|(\s+;_|\s_;+)+$|((?\<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;.\*?\1))',),'^;+|;+$',)),'(?\<=;)',' ')
> 
> Replace Genre with any other tag and it will remove duplicates too.  
> This action "fixes" first the multiple value string (remove multiple spaces after ; separator).  
> It will add exactly one space after value separator [;].
> 
> Enjoy. 😉

Hi,

Thank you very much,  
I have tried it and it works like a charm..  
Indeed I will be using it for mood tag to.

This one could definitely be in the list of examples of reg expressions.

Hartelijk bedankt  
Guy Forssman ![:w00t:](https://community.mp3tag.de/uploads/default/original/1X/cb01eca72fe9339ff6f3ec9f1e3c5fe002be0f0a.gif ":w00t:")

---

<div class="post-metadata">

### Author: ![ForSSound](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/258eb7/32.png) [@ForSSound](https://community.mp3tag.de/u/ForSSound)
#### Post date: [November 28, 2014, 9:21am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/6 "2014-11-28T09:21:28Z")

</div>

> [@Victor Kostas](#):
>
> You want to keep the first value. That's more complicated.
> 
> [Edit:]  
> Action: Format value  
> Field: Genre  
> Format string: $regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;_|\s_;+)+|(\s+;_|\s_;+)+$|((?\<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;.\*?\1))',),'^;+|;+$',)),'(?\<=;)',' ')
> 
> Replace Genre with any other tag and it will remove duplicates too.  
> This action "fixes" first the multiple value string (remove multiple spaces after ; separator).  
> It will add exactly one space after value separator [;].
> 
> Enjoy. 😉

Hi There,

On some longer metadata fields I get this error REGEXP ERROR: Regular expression

```
The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate.

```

I found a workaround by eliminating excessive ; signs

Thanks again

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [November 28, 2014, 5:30pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/7 "2014-11-28T17:30:29Z")

</div>

QUOTE (ForSSOund @ Nov 28 2014, 11:21) \<{POST\_SNAPBACK}\>

Hi There,

On some longer metadata fields I get this error REGEXP ERROR: Regular expression

```
The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent "eternal" matches that take an indefinite period time to locate.

```

I found a workaround by eliminating excessive ; signs

Thanks again

  
Simplified version.  
`$reverse($regexp($regexp(';'$reverse(%Genre%),'\s*(;[^;]+)(?=(\s*\1|;.*?\1))',),'^\s*;+|;+\s*$',))`

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [November 10, 2020, 7:03pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/8 "2020-11-10T19:03:13Z")

</div>

Hello! I tried to use this to do the same exact thing, but with " / " as a separator. Ex: World Music / Latin Jazz / Cuban

But it did not work. Hopefully someone can help me figure out why and how I can modify it to suit my needs.

I tried turning  
$reverse($regexp($regexp(';'$reverse(%Genre%),'\s\*(;[^;]+)(?=(\s\*\1|;.?\1))',),'^\s;+|;+\s\*$',))

to

$reverse($regexp($regexp(‘ / ‘$reverse(%Genre%),'\s\*(;[^;]+)(?=(\s\*\1|;.?\1))',),'^\s;+|;+\s\*$',))  
By replacing ';' with ' / ' but that resulted in  
"World Music / World Music / Latin / Latin Jazz / Latin"  
turning to  
"World Music / World Music / Latin / Latin Jazz / Latin‘ / ‘"

I also tried using the longer version turning

$regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;|\s;+)+|(\s+;|\s;+)+$|((?\<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;._?\1))',),'^;+|;+$',)),'(?\<=;)',' ')  
to  
$regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;|\s;+)+|(\s+;|\s;+)+$|((?\<=;)\s+)|(\s+(?=;))',),'^|$',’ / ‘)),'(;[^;]+)(?=(\1|;._?\1))',),'^;+|;+$',)),'(?\<=;)',' ')  
using the same method (Using replace). But that also did not work. It turned  
"World Music / World Music / Latin / Latin Jazz / " to  
"' / ‘World Music / World Music / Latin / Latin Jazz / Latin’ / ‘"

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [November 10, 2020, 7:10pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/9 "2020-11-10T19:10:38Z")

</div>

It looks a lot like the forum formatter swallowed a couple important `*`.  
I don't know, though, where.  
As a suggestion:  
you could write an action group that first replaces the slashes in your genre field with the semicolon,  
then an action to process the field with the existing expression, so that you don't have to worry about replacing the semicolon with the slash inside the expression,  
then, after rearranging the individual names an action that replaces the semicolons with the slash again.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [November 10, 2020, 9:30pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/10 "2020-11-10T21:30:37Z")

</div>

Try this one from the other thread: (I adapted it for "/" as separator)

```
$trim($regexp(%Genre%,'(?:(?<=/)|(?<=\A))\s*([^/]*)\s*/(?=.*?(?<=/)\s*\1(?=/|\Z))',,1))
```

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [November 11, 2020, 2:35am UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/11 "2020-11-11T02:35:25Z")

</div>

> Try this one from the other thread: (I adapted it for "/" as separator)

Thank you so much dano! I am not sure how it works but it does and this is a game changer for me.

Very grateful for your help. Hope it comes back around for you!

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [November 23, 2020, 3:19pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/12 "2020-11-23T15:19:50Z")

</div>

Hey dano, if you could point me to the other thread, I would appreciate it as I cannot seem to find it.

Also if you be so kind as to bold where I would change the "/" to any other separator, in case I have to modify this in the future.

I assume I would just have to change the characters in bold below from "/" to any other separator I want, but I am not sure.  
$trim($regexp(%Genre%,'(?:(?\<= **/** )|(?\<=\A))\s\*([^ **/**]_)\s_/(?=._?(?\<= **/** )\s_\1(?= **/** |\Z))',,1))

I am not sure if the "/" after the "\s\*" would need to be changed as well.

So, would  
$trim($regexp(%Genre%,'(?:(?\<=; )|(?\<=\A))\s\*([^;]_)\s_/(?=._?(?\<=; )\s_\1(?=; |\Z))',,1))

if I used "; " as a separator? Or would it have to be

$trim($regexp(%Genre%,'(?:(?\<=; )|(?\<=\A))\s\*([^;]_)\s_; (?=._?(?\<=; )\s_\1(?=; |\Z))',,1))

for some reason, neither will work when I switch from " / " to "; " as separators.

In fact, I even tried vkostas' simplified version with "; " as a separator and that did not work as well. Not sure why.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [November 23, 2020, 4:16pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/13 "2020-11-23T16:16:21Z")

</div>

> [@Doppelte Genre löschen](https://community.mp3tag.de/t/doppelte-genre-loschen/14319):
>
> Guten Tag, ich benötige Hilfe. wie kann ich im Tag Genre am Besten doppelte Einträge, getrennt durch ein Semikolum, per Batch löschen. Manuell ist dies sehr aufwändig, da ich eine größere Sammlung bereinigen möchte. Danke

You need to replace all occurrences of "/"

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [November 23, 2020, 4:29pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/14 "2020-11-23T16:29:21Z")

</div>

I thought I did, but it does not seem to work.

$trim($regexp(%Genre%,'(?:(?\<=; )|(?\<=\A))\s\*([^;])\s; (?=.?(?\<=; )\s\1(?=; |\Z))',,1))

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [November 23, 2020, 5:19pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/15 "2020-11-23T17:19:09Z")

</div>

You've put a space behind each ;

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [November 23, 2020, 7:28pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/16 "2020-11-23T19:28:57Z")

</div>

Thanks. I got that cleaned up now. Much appreciated!

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [January 6, 2021, 2:19pm UTC](https://community.mp3tag.de/t/merge-duplicate-words/16289/17 "2021-01-06T14:19:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
