Reverse the order of a list

I haven't found an answer in the forum for my specific problem, and my regex knowledge is to bad to adapt other examples to my need.
My Problem is a field with a list of words for example:US,New York,New York,Met
I would like to reverse the order of the list with a format action into:Met, New York, New York, US
to paste the result into another field.

with two more difficulties:
First there might be up to 5 comma separated values in the List, but sometimes only 1, 2 or 3.
Second the List might be separated by"," or ", " so if the regex could cater for those possibilities it would perfect. Allthouht the second i could standardize myself to ", " before.

and another problem I have, how to reverse a date from YYYY-MM-DD into DD-MM-YYYY.

I would be great if someone had a solution. just reading the regex help doesn't give me the right clues.
Or to be more correct my brain has difficulties understanding the concept.

Thank You!

Use an action of the type "Replace with regular expression" for the field.
Search string: (\d\d\d\d)-(\d\d)-(\d\d)
Replace string: $3-$2-$1

Thank You Ohrenkino!
altough I had to change it a bit, to be used in a format action.

[#0]
T=5
F=REVERSEDATE
1=$regexp(%year%,(\\\\d\\\\d\\\\d\\\\d)\\\\-(\\\\d\\\\d)\\\\-(\\\\d\\\\d),$3.$2.$1)

and I changed the "-" to ".". But i forgot to mention that before.

Have you also an idea for my first problem?

There is no built-in function "$sort()" in MP3tag (as you probably know).
There is no real function to create a loop or even loops to cylce through a list of n elements.
So you probably have to resort to the export function, export the data in a suitable format, load the data into a program, capable of sorting, reload the sorted data into Mp3tag.

Or you could create a number of actions that allow you to move the second element to front or the third or the fourth and so on. Then you don't have to do the typing, but you have to decide about the n-th element...

That sounds complicated :frowning:
I thought it would be something similar to changing first and lastname. But of course I have no idea how one would do it.

Doing it with normal actions, which scripting function would you use?

I could define the number of elments, if I had to. Leave an empty space between commas for non existing information.
Like tha: US,New York, ,Met
so I would always have the same amount of comma separated values.

Not very elegant, but with guess value I could perhaps write the information in 4 new field temp1-4 and then reorder them.
I hoped it would work without temp field, which i have to delete again later.

Thank you so far!

I searched a little more.
There is at least an idea how to get rid of duplicate words:

/t/16289/1
This might reduce the list in such a way that you either do not need the sorting any more or it can "easily" done manually ..

Thank you again!
But you missunderstood me. I don't want to get rid of any dublicates.
I just want to reverse the order of the words.

from: "US,New York,New York,Met"
to: "Met, New York, New York, US"

it is just this example where I have dublicates in the List.

It might be "DE,NRW,Düsseldorf,Philips Halle"
or just "DE,Köln"
depending on the amount of Information i have.

I now would like to reverse the order of the List to:
Philips Halle, Düsseldorf, NRW, DE
or
Köln, DE

it works with the guess value, if I have the right amount of values.

[#0]
T=7
F=%location%
1=%temp1%, %temp2%, %temp3%, %temp4%

[#1]
T=5
F=REVERSLOCATION
1=[%temp5%, ][%temp4%, ][%temp3%, ][%temp2%, ][%temp1%, ]

I just have to work on it, so it works for different numbers of values.
I hope, there would be a shorter regex to do the job, then a lot of lines of guess value action.

I do not think that the guess values action is best.
Here is a Format value for COMMENT and 4 substrings:
$regexp(%comment%,'(.),(.),(.),(.)','$4, $3, $2, $1')

Result: "US,New York,New York,Met" -> "Met, New York, New York, US"

$regexp(%comment%,'(.),(.),(.*)','$3, $2, $1') (3 parameters)
"US,New York,New York,Met" -> "Met, New York, US,New York"

$regexp(%comment%,'(.),(.)','$2, $1') (2 parameters)
"US,New York,New York,Met" -> "Met, US,New York,New York"

You will notice the "greadiness" of the first expression.

Thats it!
I had something similar before, which I cobbled together from stuff i found on the forum, but it always
produced syntax errors. That's when i gave up.

But could it be done, that one does not need three differnt actions depending on the number of values, but one expression, that does not mind the number. lets say from 1 to 5?

If not i just leave blanks between the commas. That works, it just doesn't look to smart.
But would be better anyway, so I could extract data from the list and knew which position represents which value. Like extract the towns or state.

Thank you for your help!

Action "Format value" Field: %LOCATION% Formatstring: $if($eql(4,$len($regexp(%LOCATION%,'[^,]',))),$regexp(%LOCATION%,'^(.+?), *(.+?), *(.+?), *(.+?), *(.+?)$','$5, $4, $3, $2, $1'),%LOCATION%) Action "Format value" Field: %LOCATION% Formatstring: $if($eql(3,$len($regexp(%LOCATION%,'[^,]',))),$regexp(%LOCATION%,'^(.+?), *(.+?), *(.+?), *(.+?)$','$4, $3, $2, $1'),%LOCATION%) Action "Format value" Field: %LOCATION% Formatstring: $if($eql(2,$len($regexp(%LOCATION%,'[^,]',))),$regexp(%LOCATION%,'^(.+?), *(.+?), *(.+?)$','$3, $2, $1'),%LOCATION%) Action "Format value" Field: %LOCATION% Formatstring: $if($eql(1,$len($regexp(%LOCATION%,'[^,]',))),$regexp(%LOCATION%,'^(.+?), *(.+?)$','$2, $1'),%LOCATION%)

DD.20150323.2128.CET

Action "Format value" Field: %LOCATION_COUNT% Formatstring: $len($regexp(%LOCATION%,'[^,]',)) Action "Format value" Field: %LOCATION% Formatstring: $if($eql(4,%LOCATION_COUNT%),$regexp(%LOCATION%,
          <!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->^(.+?), *(.+?), *(.+?), *(.+?), *(.+?)$<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->$5, $4, $3, $2, $1<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->%LOCATION%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc-->
Action "Format value" Field: %LOCATION% Formatstring: $if($eql(3,%LOCATION_COUNT%),$regexp(%LOCATION%,
          <!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->^(.+?), *(.+?), *(.+?), *(.+?)$<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->$4, $3, $2, $1<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->%LOCATION%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc-->
Action "Format value" Field: %LOCATION% Formatstring: $if($eql(2,%LOCATION_COUNT%),$regexp(%LOCATION%,
          <!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->^(.+?), *(.+?), *(.+?)$<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->$3, $2, $1<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->%LOCATION%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc-->
Action "Format value" Field: %LOCATION% Formatstring: $if($eql(1,%LOCATION_COUNT%),$regexp(%LOCATION%,
          <!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->^(.+?), *(.+?)$<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->$2, $1<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->%LOCATION%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc-->
Action "Format value" Field: %LOCATION_COUNT% Formatstring: $char(0) ... or ... Action "Remove tag-field" Field: %LOCATION_COUNT%

DD.20150326.1028.CET

Thank you Detlev!

Thats a neat solution. I wondered if you would find a way. It seems you usually do :slight_smile:

To understand what you have done, as I always have difficulties dissecting the regular expressions. It seems you extracted all the "," and counted them. Depending on that you have chosen the right reverse action.