# Removing duplicate fields

**URL:** https://community.mp3tag.de/t/removing-duplicate-fields/9430
**Category:** Support
**Created:** [November 27, 2009, 11:21pm UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430 "2009-11-27T23:21:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tekrotzen](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/43a26b/32.png) [@tekrotzen](https://community.mp3tag.de/u/tekrotzen)
#### Post date: [November 27, 2009, 11:21pm UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/1 "2009-11-27T23:21:18Z")

</div>

Hi!  
I'm using multiple genre fields on my mp3, and as a lot of players don't handle it that well, I'm using as well a generic genre, stored in "grouping", that I wanted to add as first genre.  
(usually, players that don't deal with multiple genre fields just use the first one available, which is perfect).

Sooo...  
Basically, if the first genre is already the same that grouping, I don't have anything to do.  
But if different, I wanted my genre field to be grouping\\genre1\\genre2\\...

To do so, I used format value on genre:

```
$if($neql($meta(genre,0),%contentgroup%),%contentgroup%\\\\$meta_sep(genre,\\\\),%genre%)

```

(I had to use %contentgroup%\\$meta\_sep(genre,\\) instead of %contentgroup%\%genre%, because only the first genre field was copied if using %genre% without meta\_sep... Is it the way it's supposed to work?)

problem is, I don't really know why, but I got a lot of duplicate fields, like Rock\\Alternative\\Alternative\\Indie\\Indie.

I was expecting it for the first genre, and it's not really a huge problem, but...  
Is there a way to remove those real duplicates?  
merge duplicates would keep those duplicated infos, and delete duplicates lose all the first genres, including the one I just added...

Thanks a lot!

PS: just found out why I have duplicate fields:  
I was splitting the genre field with character "; ", with a space, instead of ";"  
So basically the field was split with ";" AND " "...  
Still interested if you have an idea on how to remove those duplicated field though! 🙂

---

<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: [December 15, 2009, 1:08pm UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/2 "2009-12-15T13:08:20Z")

</div>

I've found a regex on regular-expressions.info that can do that:

_Action type:_ **Format value**  
_Field:_ **GENRE**  
_Format string:_ **`$regexp($meta_sep(genre,\\\\),'(?:^|(?<=\\\\))([^\\\\]*)(\\\\\1)+(?=\\\\|$)',$1)`**

The original regex is `(?<=,|^)([^,]*)(,\1)+(?=,|$)`

---

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [September 24, 2020, 11:50pm UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/3 "2020-09-24T23:50:17Z")

</div>

dano's regex didn't work for me. The following did:  
([^|]+)(|[]\*\1)+ --\> \1  
found and modified the regex found here:

> **[Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript](https://regex101.com/r/yG7zB9/8)**
>
> Regex101 allows you to create, debug, test and have your expressions explained for PHP, PCRE, Python, Golang and JavaScript. The website also features a community where you can share useful expressions.

It only works for consecutive genres (pipe delimited), so:  
blues|jazz|blues|blues --\> blues|jazz|blues

At least it's something.

---

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [September 25, 2020, 3:22am UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/4 "2020-09-25T03:22:54Z")

</div>

Further experimentation shows the following regex works better:

`(?:^|\|)([^\|]+)(\|[]*\1)+ --> \2`

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [September 26, 2020, 8:31am UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/5 "2020-09-26T08:31:11Z")

</div>

I've fixed dano's regexp from above (made the lookbehind fixed width) and changed the formatting to enclose the regexp in backticks ` so that important characters are not removed by the forum software.

---

<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:25pm UTC](https://community.mp3tag.de/t/removing-duplicate-fields/9430/6 "2021-01-06T14:25:30Z")

</div>

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