# Delete repeated genre's in the same exact field

**URL:** https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954
**Category:** Support
**Created:** [November 3, 2022, 12:06am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954 "2022-11-03T00:06:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rycia](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@Rycia](https://community.mp3tag.de/u/Rycia)
#### Post date: [November 3, 2022, 12:06am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/1 "2022-11-03T00:06:10Z")

</div>

I have looked everywhere for a solution, and have found nothing to pre-exist. All the other posts anywhere close to this either deal with multiple fields (I have just one field) named Genre, don't work, or removes everything after the first \\'s, and are several years old posts.

I have ONE genre field (not multiple,) and want to cut out duplicates out of the same (not multiple) fields.

 ![image](https://community.mp3tag.de/uploads/default/original/2X/f/f3cb5133047e225a497a372b56ef0e7988c6db79.png)

I can cut it down to this so that every word is separated and ready for it to be applied;

 ![image](https://community.mp3tag.de/uploads/default/original/2X/8/8c7dcc0ef8c9d84d1c917a5e9e95091733d84315.png)

Notice how "metal" is repeated multiple times throughout the tag, among others. It can be cut down a ton, ignore that.  
I want the duplicates of the same genre removed from the (singular) tag, each separated by \\, and not deleting anything past the first set of \'s, because I want to keep everything that isn't a duplicate.  
Here's what I want the tag to visually be from the "cut down" one;

 ![image](https://community.mp3tag.de/uploads/default/original/2X/1/1248daa241be74ca4829602517d32fdbf24ab698.png)

There's some junk in there I can filter out after, but the point is, I'm wanting to delete the genres that are repeated.

Can anybody help me figure out how to make this happen?

Here's some of the stuff I've tried;

Using "remove duplicate fields" or "merge duplicate fields" gives me this:

_Alternative_

It removes everything but the very first genre, which I don't want.

I've used various regex but the result is the same and it removes everything but the first genre.

---

<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 3, 2022, 6:13am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/2 "2022-11-03T06:13:48Z")

</div>

> [@Rycia](#):
>
> I have ONE genre field (not multiple,)

The dump that you kindly supplied shows data with a double backslash `\\` which is in MP3tag usually the indicator that there are actually multiple fields of the same type.  
Could you check the extended tags dialogue Alt-T whether how many fields of the type genre there are?  
If you find several, then merge this field into one with an action of the type

> **[Merge Duplicate Fields – Mp3tag Documentation](https://docs.mp3tag.de/actions/merge-duplicate-fields/)**
>
> Documentation on the Merge Duplicate Fields action type that can be performed as Quick Action or as reusable workflow from Action Groups. Mp3tag is the universal Tag Editor.

and use something unlike the double backslash as separator. A (comma or) semicolon would be nice.  
And then have a look at this thread:

> [@Merge duplicate words](https://community.mp3tag.de/t/merge-duplicate-words/16289/3):
>
> 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 exac…

---

<div class="post-metadata">

### Author: ![Rycia](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@Rycia](https://community.mp3tag.de/u/Rycia)
#### Post date: [November 3, 2022, 10:35pm UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/3 "2022-11-03T22:35:07Z")

</div>

> [@Merge duplicate words](https://community.mp3tag.de/t/merge-duplicate-words/16289/3):
>
> $regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;|\s;+)+|(\s+;|\s;+)+$|((?\<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;.\*?\1))',),'^;+|;+$',)),'(?\<=;)',' ')

I've messed with it for about 6 hours last night.

Yeah, everything is separated by \, and it seems like each \ creates a new field as opposed to any other separator which would otherwise define it as one single field.

I already saw that post and tried to use it with the "; " separator and it doesn't do anything at all.  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/b/b27f6ee1162ebdf2ea63d08d9aeb9c605415317e.png)

Here's the Alt-T

 ![image](https://community.mp3tag.de/uploads/default/original/2X/7/72107de8796bc0e184726eefffc9e6f947e44b95.png)  
Shows it all under one tag.

---

<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 4, 2022, 6:17am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/4 "2022-11-04T06:17:35Z")

</div>

> [@Rycia](#):
>
> I already saw that post and tried to use it with the "; " separator and it doesn't do anything at all.

That is most astounding.  
I just created a field with  
Classic; Album; Rock; Blue; Folk; Hard; Rock; Country & Rock & Roll  
Which should be reduced by 1 "Rock"  
when treated with  
`$regexp($reverse($regexp($regexp($reverse($regexp($regexp(%Genre%,'^(\s+;*|\s*;+)+|(\s+;*|\s*;+)+$|((?<=;)\s+)|(\s+(?=;))',),'^|$',';')),'(;[^;]+)(?=(\1|;.*?\1))',),'^;+|;+$',)),'(?<=;)',' ')`

And the preview in Convert\>Tag-Tag shows:  
"Classic; Album; Rock; Blue; Folk; Hard; Rock; Country & Rock & Roll" -\>  
"Classic; Album; Rock; Blue; Folk; Hard; Country & Rock & Roll"  
which I think is just about right.  
I also used it on  
"Alternative; Metal; English; Groove; Nu-Metal; Heavy; Nu; Charts; Rock; Indie; Rock; Thrash" -\>  
"Alternative; Metal; English; Groove; Nu-Metal; Heavy; Nu; Charts; Rock; Indie; Thrash"

and this would lead me to the statement: works as designed.

---

<div class="post-metadata">

### Author: ![Rycia](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/c67d28/32.png) [@Rycia](https://community.mp3tag.de/u/Rycia)
#### Post date: [November 9, 2022, 11:05pm UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/5 "2022-11-09T23:05:59Z")

</div>

Okay, so the issue was I was trying to automate this through Actions \> Actions and making an action using "Replace with regex," when I should had been using Convert \> Tag - Tag and putting in;

> GENRE

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

Everywhere I looked otherwise didn't explain this very well.

Would be nice if MP3Tag added that function under with Convert as well to automate it, because any way i've done it that way didn't work.

---

<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, 2022, 6:34am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/6 "2022-11-10T06:34:13Z")

</div>

> [@Rycia](#):
>
> Would be nice if MP3Tag added that function under with Convert

Or an action of the type "Format value". So there is no single place.  
$Regexp() is a scripting function and may be used where a "format string" is required.  
The action of the type "Replace with regular expression" asks for a source pattern (or something similar but no format string).  
Also, you did not say in which action you tried to get it working.  
Yet, the linked thread clearly states

> [@Merge duplicate words](https://community.mp3tag.de/t/merge-duplicate-words/16289/3):
>
> Action: Format value

So ...

---

<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: [December 10, 2022, 6:34am UTC](https://community.mp3tag.de/t/delete-repeated-genres-in-the-same-exact-field/58954/7 "2022-12-10T06:34:51Z")

</div>

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