# Merging several Tag Fields into CONTENTGROUP

**URL:** https://community.mp3tag.de/t/merging-several-tag-fields-into-contentgroup/10616
**Category:** Support
**Created:** [July 4, 2010, 10:31pm UTC](https://community.mp3tag.de/t/merging-several-tag-fields-into-contentgroup/10616 "2010-07-04T22:31:01Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [September 21, 2010, 5:30am UTC](https://community.mp3tag.de/t/merging-several-tag-fields-into-contentgroup/10616/4 "2010-09-21T05:30:20Z")

</div>

> [@DetlevD](#):
>
> ... to be continued ...

... and here it goes ...

Note:  
If we could sort a delimited itemlist within a tag-field, Mp3tag life would be much easier!  
If we could repeat one action in a loop, Mp3tag life would be much easier!

Example itemlist:  
ITEMLIST="aaa,aaa,aaa,bbb,ccc,bbb,ddd,ddd,ddd,ccc,eee,fff,GGG,ggg,iii"

The itemlist contains 15 items:  
"aaa" x 3, "bbb" x 2, "ccc" x 2, "ddd" x 3, "eee" x 1, "fff" x 1, "GGG" x 1, "ggg" x 1, "iii" x 1.

This regular expression:  
`$regexp(%ITEMLIST%,'(?:^|,)([^,]*)(,\1)+(?=,|$)','$2')`  
will reduce the itemlist by removing adjacent duplicate items  
from:  
"aaa,aaa,aaa,bbb,ccc,bbb,ddd,ddd,ddd,ccc,eee,fff,GGG,ggg,iii"  
to:  
",aaa,bbb,ccc,bbb,ddd,ccc,eee,fff,GGG,ggg,iii"

This regular expression:  
`$regexp(%ITEMLIST%,'(?:^|,)([^,]*)(.*)(,\1)+(?=,|$)',',$1$2')`  
will further reduce the itemlist by one duplicate pair  
from:  
",aaa,bbb,ccc,bbb,ddd,ccc,eee,fff,GGG,ggg,iii"  
to:  
",aaa,bbb,ccc,ddd,ccc,eee,fff,GGG,ggg,iii"

There are still some duplicate items in the itemlist.  
Mp3tag cannot execute an action in a loop, so we have to sequentially repeat this step.  
How much? Use a count that fits to your needs.

After some steps the itemlist will be reduced  
from:  
",aaa,bbb,ccc,bbb,ddd,ccc,eee,fff,GGG,ggg,iii"  
to:  
",aaa,bbb,ccc,ddd,eee,fff,GGG,ggg,iii"

Surrounding comma can easily be trimmed by  
`$trim(%ITEMLIST%,',')`

Now the itemlist contains nine unique mixcased items:  
ITEMLIST="aaa,bbb,ccc,ddd,eee,fff,GGG,ggg,iii"

If the process should not respect mixcased items, that means ignore mixcased spelling, then the regular expressions need a modification:  
`$regexp(%LIST%,'(?i)(?:^|,)([^,]*)(,\1)+(?=,|$)','$2')`  
`$regexp(%LIST%,'(?i)(?:^|,)([^,]*)(.*)(,\1)+(?=,|$)',',$1$2')`  
This will reduce the itemlist  
from:  
"aaa,aaa,aaa,bbb,ccc,bbb,ddd,ddd,ddd,eee,fff,GGG,ggg,iii"  
to:  
",aaa,bbb,ccc,ddd,eee,fff,ggg,iii"

Put all steps into an action group:  
[Test\_2010\_20100921.RemoveDupItems.mta](https://community.mp3tag.de/uploads/default/original/2X/e/e92e70585333d2bb90e81954a94257f616ffb93c.mta) (1021 Bytes)

Now it is possible to do ...  
From:  
ITEMLIST="Female Vocalists, Indie, Indie Rock, Alternative, Rock, Indie Pop, Pop/Rock, Alternative Rock, Punk, Indie Rock, Alternative/Indie Rock, Alternative Pop/Rock, Fun, Garage Rock Revival, Alternative Rock, Bright, FUN, Stylish, Uplifting, Nostalgic, Exciting, Fun, Girls Night Out, FUN, Breakup, Indie Rock"  
To:  
ITEMLIST="Female Vocalists, Indie, Indie Rock, Alternative, Rock, Indie Pop, Pop/Rock, Alternative Rock, Punk, Alternative/Indie Rock, Alternative Pop/Rock, Fun, Garage Rock Revival, Bright, Stylish, Uplifting, Nostalgic, Exciting, Girls Night Out, Breakup"

... alas ... still not sorted!

DD.20100921.0930.CEST

---

_[View the full topic](https://community.mp3tag.de/t/merging-several-tag-fields-into-contentgroup/10616)._
