# Turning "Firstname Lastname" Album Artists into "Lastname, Firstname" Album Artist Sort

**URL:** https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940
**Category:** Mac
**Created:** [December 23, 2024, 6:11pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940 "2024-12-23T18:11:20Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 23, 2024, 6:11pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/1 "2024-12-23T18:11:20Z")

</div>

I have several different formulae for filing albums, based on whether to include the disc number, track artist, etc. They're all organized, at the top level, by the albumartistsort value or, if that would be the same as the albumartist, by that albumartist value. (For example, I could just use "Journey" or "Neutral Milk Hotel" as is.)

Frequently, however, the artist has a Firstname Lastname, such as "John Lennon". I would love to create an action that could swap that into "Lastname, Firstname" for sorting. I recognize that this would not be good as a default action (for example, I know that "Jethro Tull" or "Moxy Fruvous" would not get swapped), but in the many situations in which I see that I would have to do this by hand, I would love to have an action to do this automatically.

I'm pretty sure that this could be done with the tagging tools, but I haven't figured this out. Does anyone already have a formula to do this?

---

<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: [December 23, 2024, 6:15pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/2 "2024-12-23T18:15:42Z")

</div>

There are several solutions already available in this forum.  
Please use the search function with words like  
[swap firstname lastname](https://community.mp3tag.de/search?q=swap%20firstname%20lastname%20order%3Alatest)

And please be aware the many exceptions that exists beside group names, like artists with multiple parts in the name as "The Artist formerly known as Prince" or combinations like "Bob Marley & The Wailers".

BTW: Do you remember your own similar question here:

> [@Add space to, swap Lastname,Firstname](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/5):
>
> Before I reinvent the wheel: Is there a known way to do something like the reverse, to change a field with, say, "John Coltrane" to "Coltrane, John" by swapping the words and placing a comma after the one moved to the first position? I do this a lot by hand (and realize that I would have to look at the contents before doing it to avoid messing up "Jethro Tull").

including the Howto answer:

> [@Regular Expressions](https://community.mp3tag.de/t/regular-expressions/521/6):
>
> Another one, that switches first and last names (for instance, Jacques Brel will become Brel, Jacques: Regular Expression:^(.+)\s(.+)$ Replace with: $2, $1

---

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 23, 2024, 9:30pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/3 "2024-12-23T21:30:13Z")

</div>

I actually hadn't remembered that I had asked before. I have used regular expressions in the past, but I'm not understanding something about the syntax here.

I see that, according to the docs, regexps work like `$regexp(x,e,r,c)` where " $regexp(x,e,r,c)` replaces the pattern specified by the [regular expression](https://docs.mp3tag.de/regex) e in the string x by r."

It appears that I would put that in the action as  
$regexp(%ALBUMARTIST%, something)

But I'm not getting how the suggested  
Regular Expression:^(.+)\s(.+)$ Replace with: $2, $1  
fits in there.

I have tried replacing the "something" with  
$regexp(%albumartist%,^(.+)\s(.+)$)  
which does nothing.

I suspect that I may have to set the "r" value to  
$2, $1  
but the comma in there confuses me. It appears that it if I would change it to  
$regexp(%albumartist%,^(.+)\s(.+)$,$2,$1)  
the $1 would be considered as the "e" value.

I'm probably missing just one bit of information as to how the syntax works, and I'm not spotting it in the docs or the community conversations. It's probably one of those things that will appear obvious to those who already know it.

---

<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: [December 23, 2024, 10:25pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/4 "2024-12-23T22:25:23Z")

</div>

In which field do you have your example  
John Lennon  
in the ALBUMARTIST or ARTIST?

To swap the firstname with the lastname you can use for example an Action "Replace with regular expression"

Field:  
`ARTIST`  
Regular expression:  
`(.*) (.*)`  
Replace matches with:  
`$2, $1`

 ![image](https://community.mp3tag.de/uploads/default/original/3X/5/9/59cb09881d2b609331e1855fc8bb3ba21f7b9e77.png)

As already mentioned, this only works for ARTIST content with two parts like John Lennon. It does not work for 3 or more parts in the name.

Please use such an Action carefully and apply it only to specific tracks.

Explanation for the regular expression:  
Group together all characters before the last space (=`$1`)  
Group together all characters after the last space (=`$2`)  
then  
Replace the current content with the content of  
`$2` followed by a comma and a space  
and the content of `$1`

This should explain why this regular expression does not work for example for  
John Ringo Lennon (would become "Lennon, John Ringo")  
or  
John Ringo Starr Lennon (would become "Lennon, John Ringo Starr")

---

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 23, 2024, 11:03pm UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/5 "2024-12-23T23:03:08Z")

</div>

How do you get that dialog to appear? I've never seen it before. I have been editing my Actions from the Actions \> Actions menu.

---

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 24, 2024, 5:24am UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/6 "2024-12-24T05:24:05Z")

</div>

OK, I found that dialog (under a toolbar button that only had a graphic that I wouldn't have guessed would mean that and selecting "Replace with regular expression). Putting those values in that box worked for doing it for a single instance. Thanks.

Now back to the question that I’m trying to figure out: how would I put it into a repeatable, named action, to set the value of ALBUMARTISTSORT based on doing this to the value of ALBUMARTIST?

This is what I have so far. I still need to understand how that "$2, $1" fits in that syntax.

 ![image](https://community.mp3tag.de/uploads/default/original/3X/f/8/f815361d5ca3ffefb89c73a44e132442ec957db4.jpeg)

---

<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: [December 24, 2024, 7:34am UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/7 "2024-12-24T07:34:05Z")

</div>

Oh, you are on a Mac!  
Why didn't you say so?  
Have a look at the documentation:

> [@Quick Actions and Action Groups](https://community.mp3tag.de/t/quick-actions-and-action-groups/51882):
>
> Mp3tag for Mac provides a variety of Actions, which can be used on filenames and tags. The actions can be applied individually via Actions → Quick Actions ⌥⌘ 6 or be grouped into named and reusable Action Groups via Actions → Actions ⌘ 6. Action Groups serve as repeatable workflows in Mp3tag for Mac. When using Quick Actions you can select one of the different available action types from the list. This action will be applied to the selected files and the changes are saved immediately. Tip 1…

---

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 24, 2024, 8:49am UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/8 "2024-12-24T08:49:21Z")

</div>

Oh! You're right, that's a significant omission on my part. I am, indeed, on a Mac.

---

<div class="post-metadata">

### Author: ![josephzitt](https://community.mp3tag.de/user_avatar/community.mp3tag.de/josephzitt/32/9533_2.png) [@josephzitt](https://community.mp3tag.de/u/josephzitt)
#### Post date: [December 24, 2024, 9:21am UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/9 "2024-12-24T09:21:35Z")

</div>

Followup: After the welcome help here, digging through docs, and several hours of trial and error. I think I have it working.

Applying my action 'Move Files (Swap)' to an album by the ALBUMARTIST Brian Eno, with the value:

Format field "\_DIRECTORY":/Volumes/PublicXL/data/media/music/$regexp(%albumartist%,^(.+)\s(.+)$,'$2, $1')/%YEAR% %ALBUM%/  
resulted in the hoped-for path:

/Volumes/PublicXL/data/media/music/Eno, Brian/2017 Reflection/

The missing piece was to put the last argument to the regexp, '$2, $1', in single quotes.

Thanks, all. Hopefully, having it here will help the next person who trips over this.

---

<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 23, 2025, 9:21am UTC](https://community.mp3tag.de/t/turning-firstname-lastname-album-artists-into-lastname-firstname-album-artist-sort/66940/10 "2025-01-23T09:21:54Z")

</div>

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