# Create A New Action to swap first name last name to last name, first name

**URL:** https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006
**Category:** Support
**Created:** [September 22, 2024, 4:28pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006 "2024-09-22T16:28:49Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![IdrisR](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@IdrisR](https://community.mp3tag.de/u/IdrisR)
#### Post date: [September 22, 2024, 4:28pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/1 "2024-09-22T16:28:49Z")

</div>

I have downloaded MP3TAG to a new computer and require some assistance.  
Stupidly I did not take a backup of my original which had purpose made 'ACTIONS'

I have lost my copy of the syntax code to create 2 separate 'Actions'

1. To enable ARTISTSORT to convert for example, (Artist) Elvis Presley to Artistsort) Presley, Elvis.

2. To enable ARTISTSORT to convert for example (Artist) The Beatles to (Artistsort) Beatles, removing the 'The' from group names.

I would appreciate some help.

A Basic 'Idiots' Guide in creating the actions would be appreciated.

thanks

---

<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: [September 22, 2024, 4:43pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/2 "2024-09-22T16:43:03Z")

</div>

See e.g. here:

> [@First Name Last Name with any frailing words to Last Name, First Name and Trailing words](https://community.mp3tag.de/t/first-name-last-name-with-any-frailing-words-to-last-name-first-name-and-trailing-words/59734):
>
> I have been using this Action to switch a simple First Name Last Name to Last Name, First Name: Replace with regular expression: Regular Expression ^([^,]+)\s([^,]+)$ Replace with: $2, $1 One reason why I use this is because it will not modify names already in the Last Name, First Name format. Ex: Brel, Jacques William remains Brel, Jacques William with the above action. How can I modify it to work with trailing words behind a first and last name? So Alton Ellis & The Lipsticks would beco…

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 22, 2024, 10:58pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/3 "2024-09-22T22:58:59Z")

</div>

For the first you could create an action like this:  
 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/1/7/17c729faac607b74b4250fa28536c72f6e409984.png)

```auto
$regexp(%artist%,(.*) (.*),$2',' $1)

```

This creates (or overwrites) ARTISTSORT like you want.  
But as soon as you have more than one artist or artists that are bands instead of people it stops working. Depending on how your artists are named you could enhance the regex to work for multiple patterns, like "artist A, artist B" or "artist A, artist B & artist C" etc.. but you should always filter before using the action and check the results.

For the second you can be more specific:  
 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/e/4/e4c66f7257641816cffa8349ffa3542a6823ad65.png)

```auto
$regexp(%artist%,^The (.*),$1)

```

---

<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: [September 23, 2024, 5:12am UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/4 "2024-09-23T05:12:45Z")

</div>

If the "the" messes up the sorting (which I can understand as the Beatles called themselves "The Beatles" and occasionally just "Beatles" which would lead to some entries to be found under "B" and others under "T"...) I would still look at it with a sober glance and estimated rationally:  
Does the "the" really determine the correct sorting order or aren't all the name parts in front of the "the" already enough to get it sorted correctly?  
I would assume that the existence of "the" does not change anything. So I would simply leave that out which means: just delete the leading "The".  
And even this simple rule has its exceptions as artists like "The Band" or "The The" simply are not the same without the "The".

And for all the other names I am still of the opinion that it does not make any sense as there would be too many exceptions so that finding artists will not become any easier.  
Which means: in general, leave every artist name as it is.  
Any decent player will look for name parts and group all the hits together.  
Scrolling through lists of artists just to see what is there will become an exhausting and time consuming method if you have more then (say) 50 different ones.

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 23, 2024, 8:47am UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/5 "2024-09-23T08:47:27Z")

</div>

> [@ohrenkino](#):
>
> the Beatles called themselves "The Beatles" and occasionally just "Beatles" which would lead to some entries to be found under "B" and others under "T"...)

For my own collection I've "solved" this issue by pretty much ignoring the "artist" and unifying the albumartist. Artist remains whatever was on the cover of the album, while albumartist gets the standard name of the main responsible person/band (or multiple). Some people even change their name multiple times over the course of their career. Otherwise I would never ever find stuff that belongs together without going to discogs/wikipedia first.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [September 23, 2024, 9:00am UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/6 "2024-09-23T09:00:47Z")

</div>

Interesting!  
So - for example - do you use "Cat Stevens" as ALBUMARTIST even for his releases as "Yusuf Islam"?  
Or do you use his real name "Steven Demetre Georgiou"?

---

<div class="post-metadata">

### Author: ![poster](https://community.mp3tag.de/user_avatar/community.mp3tag.de/poster/32/4881_2.png) [@poster](https://community.mp3tag.de/u/poster)
#### Post date: [September 23, 2024, 10:16am UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/7 "2024-09-23T10:16:11Z")

</div>

You Remember?

> [@How to cope with artists who change their name](https://community.mp3tag.de/t/how-to-cope-with-artists-who-change-their-name/58223):
>
> How would you tag the albums of a band which decided to change it's bandname from "Mandolin Orange" in "Watchhouse" in 2021, had 6 albums under name of "Mandolin Orange" from 2010-2019 and 1 album under name of "Watchhouse" (2021). It's not just that they have this new name for their latest album. They seem to use this new name also for their older releases and record shops and streaming services already list the old releases under the new bandname, partly with a hint (formerly called "Mandoli…

Sometimes you have to creative. 😉

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 23, 2024, 10:48am UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/8 "2024-09-23T10:48:20Z")

</div>

> [@LyricsLover](#):
>
> So - for example - do you use "Cat Stevens" as ALBUMARTIST even for his releases as "Yusuf Islam"?

Usually the name the artist is best known as, so to a degree it's arbitrary or rather depends on which name I know best. The upside is that since I don't touch the artist, services like lastfm still work correctly as they only scrobble title/artist/album. I pretty much only use my library by albumartist.  
Another quirk is that I also use the albumartist for tribute albums.  
For example: "One Of These Days - Plays Pink Floyd" by "The Royal Philharmonic Orchestra" gets a secondary albumartist of "Pink Floyd V.A." for me. That way I can click on Pink Floyd V.A. directly under Pink Floyd and get all the tribute albums in one place. Which is especially useful for tribute albums where the bands name is not part of the album title. Otherwise I'd never ever find them again.

---

<div class="post-metadata">

### Author: ![IdrisR](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@IdrisR](https://community.mp3tag.de/u/IdrisR)
#### Post date: [September 23, 2024, 12:44pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/9 "2024-09-23T12:44:41Z")

</div>

Thanks for your help.

So your first string would change sort to show surname first eg: Presley, Elvis

Second string would remove 'The' from group names (The Beatles would change to Beatles)

Could you advise how to have these 2 actions for the ARTISTSORT String?

I did have separate entries in my drop down action list on my previous computer so I know it can be done.

Once again thank you for your help

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 23, 2024, 1:03pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/10 "2024-09-23T13:03:16Z")

</div>

These 2 actions create/change the ARTISTSORT tag depending on the content of the ARTIST tag.  
If ARTIST is Elvis Presley, action 1 sets ARTISTSORT to Presley, Elvis.  
If ARTIST is The Beatles, action 2 sets ARTISTSORT to Beatles.

---

<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: [September 23, 2024, 1:09pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/11 "2024-09-23T13:09:53Z")

</div>

> [@IdrisR](#):
>
> So your first string would change sort to show surname first eg: Presley, Elvis
> 
> Second string would remove 'The' from group names (The Beatles would change to Beatles)

If you execute the 2 actions in that order, then I assume that the second will not remove any leading "the" as the first action has already moved the "the" to the end.  
Also watch out for exceptions like "The The", "The Band", "The Weeknd", "The XX"

---

<div class="post-metadata">

### Author: ![IdrisR](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@IdrisR](https://community.mp3tag.de/u/IdrisR)
#### Post date: [September 23, 2024, 1:21pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/12 "2024-09-23T13:21:03Z")

</div>

So how do I create 2 separate actions as you describe under ARTISTSORT tag.

I created the first string of your examples and it changed to Presley, Elvis (Great)

I created a second string named (Remove 'The') and altered the string to your second example, it cleared previous altered sort names and did nothing to removing 'The' from group names.  
When I had it working before. I Would select all groups with 'The' in their name, apply the action and it would remove 'The'  
I Had two separate actions.  
I Am not able to create two this time.  
Thanks

---

<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: [September 23, 2024, 1:24pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/13 "2024-09-23T13:24:03Z")

</div>

> [@IdrisR](#):
>
> So how do I create 2 separate actions as you describe under ARTISTSORT tag.

Here is a description in the FAQs how to create an action group.

> [@Actions and batch-operations](https://community.mp3tag.de/t/actions-and-batch-operations/967/2):
>
> How to create a new action? First, create a new action group via Actions \> [Actions] Actions or Alt + 6. Then, click on the button [New] New and give your action group an expressive name, e.g., "All tag fields Upper Case". This action group can be applied to the selected files after you have added one or more actions to it. Now, you can create a new action in your action group via the button [New] New and choose the desired action type from the list. At the moment the following action types …

If you want to get 2 separate action groups, you have to do that twice.

---

<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: [September 23, 2024, 1:30pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/14 "2024-09-23T13:30:59Z")

</div>

> [@IdrisR](#):
>
> I created the first string of your examples and it changed to Presley, Elvis (Great)

Just use this action carefully as that action (and/or MP3tag) cannot read. It simply swaps the defined parts around and adds a comma in between.  
So, "Huey Lewis & The News" would become "Lewis & The News, Huey".  
Other groups that clearly do not feature a first name / last name structure like  
Aural Float  
Deep Purple  
Global Youth  
Rolling Stones  
and many, many more  
would get their names altered  
I would never expect "Depeche Mode" to be found under "M" for "Mode, Depeche".

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 23, 2024, 1:35pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/15 "2024-09-23T13:35:15Z")

</div>

> [@IdrisR](#):
>
> it cleared previous altered sort names and did nothing to removing 'The' from group names.

Sorry about that. I forgot that mp3tag is a bit overactive when you use $regexp. I wish there was an option to simply abort if no match is found instead of using the input string as the output.

You can work around this limitation like this:

```auto
$if($neql($regexp(%artist%,^The (.*),$1),%artist%),$regexp(%artist%,^The (.*),$1),%artistsort%)

```

This checks if the match in the regex is equal to the artist tag (which means no match), in which case ARTISTSORT is left alone. If it's not equal (match found), it removes the "The" and saves the resulting string to ARTISTSORT.

I've gone ahead and created both actions, you can drop them in:

```auto
C:\Users\USER\AppData\Roaming\Mp3tag\data\actions

```

if you have trouble creating them yourself.  
[&A ARTISTSORT#&A First Last → Last, First.mta](https://community.mp3tag.de/uploads/short-url/nS84z2LMPTYyq1HDDw5U87f2Jj1.mta) (70 Bytes)  
[&A ARTISTSORT#&B Remove The.mta](https://community.mp3tag.de/uploads/short-url/krN0N8M4wkA3yIWC9GONEsOGgNa.mta) (129 Bytes)

---

<div class="post-metadata">

### Author: ![IdrisR](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@IdrisR](https://community.mp3tag.de/u/IdrisR)
#### Post date: [September 23, 2024, 1:42pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/16 "2024-09-23T13:42:39Z")

</div>

Right I have added both of your suggested actions.  
1st action works perfectly  
2nd action works perfectly

I would be interested if you had any suggestions of reading / learning material for basic syntax coding? I feel it is only the tip of the iceberg what can be achieved if I had the correct code.  
Brilliant.  
Thanks for your help.

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [September 23, 2024, 1:47pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/17 "2024-09-23T13:47:40Z")

</div>

> [@IdrisR](#):
>
> I feel it is only the tip of the iceberg what can be achieved if I had the correct code.  
> Brilliant.

If you mean programming as such, I can recommend this [Python course](https://www.youtube.com/watch?v=nLRL_NcnK-4) which covers most of the basics. The instructor is great.

The principles are pretty much the same, the only thing that differs is the syntax. For regular expressions, [this video](https://www.youtube.com/watch?v=sa-TUpSx1JA) is a good introduction.

But it also helps to just play around with regex yourself.  
I usually use [RegExr](https://regexr.com/) to test my regexes and [Regexper](https://regexper.com/) to visualize them (this often reveals common pitfalls like using `.` instead of `\.` for example.

Good luck. 🙂  
And feel free to ask for some more regex help. I'm the rare breed of deviant that enjoys regex.

---

<div class="post-metadata">

### Author: ![IdrisR](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@IdrisR](https://community.mp3tag.de/u/IdrisR)
#### Post date: [September 23, 2024, 7:01pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/18 "2024-09-23T19:01:31Z")

</div>

I understand your logic, but my music system displays Artists as they normally appear for example: (Artist Name) Chris Rea (Sort Name) Rea, Chris. (Artist Name) Marvin Gaye & Tammy Terrell (Sort Name) Gaye, Marvin; Terrell, Tammy (Artist Name)The Beatles (Sort Name) Beatles.  
I search for any Artist by Surname / Group and the correct artists are shown.  
I use dbpoweramp excellent Asset programme for creating the metadata within my music files, and everything works as it should.

---

<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: [October 23, 2024, 7:02pm UTC](https://community.mp3tag.de/t/create-a-new-action-to-swap-first-name-last-name-to-last-name-first-name/66006/19 "2024-10-23T19:02:04Z")

</div>

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