# Switching first and last name of Artist

**URL:** <https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020>\
**Category:** Support\
**Created:** [October 28, 2010, 4:57pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020 "2010-10-28T16:57:38Z")\
**Posts on this page:** 13\
**Page:** 2

<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:** [February 20, 2021, 8:50pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/21 "2021-02-20T20:50:49Z")

</div>

If you know how many of these multi-value fields you have then you can use for the above example 2 action:  
`$regexp($meta(artist,0),'(.*?) (.*)','$2, $1')`  
`$regexp($meta(artist,1),'(.*?) (.*)','$2, $1')`

---

<div class="post-metadata">

**Author:** ![Flskydiver](https://community.mp3tag.de/user_avatar/community.mp3tag.de/flskydiver/32/8129_2.png) [@Flskydiver](https://community.mp3tag.de/u/Flskydiver)\
**Post date:** [February 20, 2021, 9:00pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/22 "2021-02-20T21:00:47Z")

</div>

So, yeah, that sounds like you need to create something for a “B, A \ D, C” —\> “A B \ C D”.

You’d need a different action for each number of collaborators and the separator ( \ ) would have to be identical for each one, or some sort of script written to change up to as many collaborators as you need ( F, E \ H, J ... etc.) but return null once the final separator is detected.

My collection didn’t have a bunch of those, so I found it easier to just edit those by hand. I never modified anything for that scenario.

---

<div class="post-metadata">

**Author:** ![Bullfrog](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@Bullfrog](https://community.mp3tag.de/u/Bullfrog)\
**Post date:** [July 29, 2022, 4:42pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/23 "2022-07-29T16:42:36Z")

</div>

I have a bunch of mp3s that have the tag listed as 'lastname, firstname' and want it 'firstname lastname' In searching for a solution I ran across this thread, however, I have an issue. The answer given by Flskydiver was:

Action: Format Value  
Field: ARTIST  
Fromatstring: `$regexp(%artist%,(.*)',' (.* ),$2 $1)`

The change I want is

Warner, Steve ---\> Steve Warner

What I get is

Warner, Steve ---\> WarineS rteve

I triple checked the code given. What am I doing wrong?

---

<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:** [July 29, 2022, 4:48pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/24 "2022-07-29T16:48:59Z")

</div>

> [@Bullfrog](#):
>
> Fromatstring: `$regexp(%artist%,(.*)',' (.* ),$2 $1)`

Try  
Format string: `$regexp(%artist%,'(.*), (.*)',$2 $1)`

Take care of those artists that have the comma deliberately like Bell, Book & Candle, Earth, Wind & Fire, Emerson, Lake & Palmer etc.

---

<div class="post-metadata">

**Author:** ![Bullfrog](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@Bullfrog](https://community.mp3tag.de/u/Bullfrog)\
**Post date:** [July 29, 2022, 5:05pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/25 "2022-07-29T17:05:02Z")

</div>

> [@ohrenkino](#):
>
> `$regexp(%artist%,'(.*), (.*)',$2 $1)`

Brilliant!!!! worked great, Thank You!!

---

<div class="post-metadata">

**Author:** ![pstrisik](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/6a8cbe/32.png) [@pstrisik](https://community.mp3tag.de/u/pstrisik)\
**Post date:** [December 1, 2022, 11:53pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/26 "2022-12-01T23:53:40Z")

</div>

Opening this up again as I have all of my files with AlbumArtist as Last, First.

With the help of those in this thread 🫵 👍, I have these expressions that copy AlbumArtist to AlbumArtistSort so they will sort that way, then transform AlbumArtist to First Last. Both in one action.

Format value "ALBUMARTISTSORT": $if2(%ALBUMARTISTSORT%,%ALBUMARTIST%)  
Format value "ALBUMARTIST": `$regexp(%albumartist%,'(.*), (.*)',$2 $1)`

Works well for most cases.

Anyone want to take a stab at an AlbumArtist in the form: Last, First & Last, First? The second comma messes things up.

I also want to be able to apply these expressions to a large number of files and don't want to have a lot of manual tasks. So the flow would be something like:

copy albumartist to albumartistsort  
if albumartist is Last, First & Last, First, replace with Last, First & First Last  
then ohrenkino's expression: `$regexp(%artist%,'(.*), (.*)',$2 $1)` from post 24

Accomplishing this would probably correctly treat 90%+ of cases. I'm sure I'll find another one or two that don't work with this.

So, it's the second of the three lines that I need help with.

Anyone? Many 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:** [December 2, 2022, 6:59am UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/27 "2022-12-02T06:59:54Z")

</div>

> [@pstrisik](#):
>
> if albumartist is Last, First & Last, First, replace with Last, First & First Last

You could try  
`$regexp('Last, First & Last, First','(.*), (.*) & (.*), (.*)',$2 $1 & $4 $3)`  
as the second action, then the one that swaps without ampersand

> [@pstrisik](#):
>
> I also want to be able to apply these expressions to a large number of files and don't want to have a lot of manual tasks

Then I would filter for the files that they really match the patterns.  
Earth, Wind & Fire would become Wind & Fire Earth with the first expression.  
And this mixture applies to most other band names with a comma and an ampersand.  
So I doubt that you can run it all on its own.

---

<div class="post-metadata">

**Author:** ![pstrisik](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/6a8cbe/32.png) [@pstrisik](https://community.mp3tag.de/u/pstrisik)\
**Post date:** [December 2, 2022, 2:59pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/29 "2022-12-02T14:59:10Z")

</div>

Thank you ohrenkino! 👏🏼

I now have:

![image](https://community.mp3tag.de/uploads/default/original/2X/0/0eaf624aa52a1b7ce7487b7656915917d34b3b23.png)

Here are example cases I identified so far that don't work (before / after)

Yamash'ta, Stomu / Yamash'ta, Stomu  
Milteau, Jean-Jacques / Jean Milteau-Jacques  
Earth, Wind & Fire / Wind Earth & Fire  
Ndegéocello, Me'Shell / Me Ndegéocello'Shell  
Scott-Heron, Gil / Scott-Heron, Gil  
Coryell, Bailey, White / Bailey Coryell, White

I'll play with tweaking the expressions, but I think I am also at the point where I can search for and modify the edge cases manually so they will behave before doing mass operations.

---

<div class="post-metadata">

**Author:** ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)\
**Post date:** [December 2, 2022, 3:33pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/30 "2022-12-02T15:33:50Z")

</div>

> [@pstrisik](#):
>
> Earth, Wind & Fire / Wind Earth & Fire

This is an exact example that was given above by @ohrenkino to watch for. There are almost always fringe cases like these that are prime examples of why it isn't a good idea to run any operation on a huge number of files without knowing there could be undesired results.

But knowing that these do exist for such a small group, you can then make the necessary changes to these manually to have them conform to how you prefer them in your library.

---

<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:** [December 6, 2022, 2:24am UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/31 "2022-12-06T02:24:06Z")

</div>

> [@pstrisik](#):
>
> before doing mass operations

I'd never run something like this over more than a few hundred tracks at a time. And even then only if you look through them before and after you run it. I like having all my artists and album artists separated with ; instead of stuff like: John Zorn, Laura Nyro & Johnny "Big Moose" Walker (featuring. Joni Mitchell Quartet).  
Which is why I first treat the artist field with this:  
 ![grafik](https://community.mp3tag.de/images/transparent.png)

The field I really care about is album artist tho, which is what I sort by last name.  
The first action transforms:  
John Zorn, Laura Nyro & Johnny "Big Moose" Walker (featuring. Joni Mitchell Quartet)  
into  
John Zorn; Laura Nyro; Johnny "Big Moose" Walker; Joni Mitchell Quartet

I've got another action to copy that to the album artist tag if there's garbage in the album artist tag I want to overwrite (I only put the main artist into the album artist field tho, not featured artists).

```auto
Field:
ALBUMARTIST

Regular expression:
([^;]+\s?[^;]+(?:\s?[^;]+)?)\s(?!Trio|Quartet|Quartetto|Quintet|Sixtet|Sestetto|Septet|Octet|Ottetto|Orchestra|Chamber Orchestra|Ensemble)([^;]+)

Replace matches with:
$2, $1

```

This then turns  
John Zorn; Laura Nyro; Johnny "Big Moose" Walker; Joni Mitchell Quartet  
into  
Zorn, John; Nyro, Laura; Walker, Johnny "Big Moose"; Mitchell, Joni Quartet

If you keep or lose the "Quartet" part is up to personal preference. I usually delete it from the album artist as it's already in the artist field and only keep the name.

It's not perfect and I strongly advise that you try to understand every part of it before you use it on many files at once but for me it has greatly reduced the amount of manual editing of tags.  
If anyone has suggestions to improve my actions, I'm always all ears.

---

<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 6, 2022, 7:04am UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/32 "2022-12-06T07:04:44Z")

</div>

> [@Casual\_Tea](#):
>
> This then turns  
> John Zorn; Laura Nyro; Johnny "Big Moose" Walker; Joni Mitchell Quartet  
> into  
> Zorn, John; Nyro, Laura; Walker, Johnny "Big Moose"; Mitchell, Joni Quartet

Even though this action will certainly do as you say, I still think that it is a vain effort - as soon as you get "Zorn" into ARTISTSORT then all the other artists in that line will probably be ignored. So for a correct order, John Zorn would have been enough in most cases.

---

<div class="post-metadata">

**Author:** ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)\
**Post date:** [January 24, 2023, 4:09pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/33 "2023-01-24T16:09:54Z")

</div>

> [@ohrenkino](#):
>
> > [@Bullfrog](#):
> >
> > Fromatstring: `$regexp(%artist%,(.*)',' (.* ),$2 $1)`
> 
> Try  
> Format string: `$regexp(%artist%,'(.*), (.*)',$2 $1)`

I have tried both versions of this and both have worked. Which is the correct version to use? I may not have come across something that may have an issue with either one, but that does not mean there is not something that will, so I want to use the proper one.

Also, for some reason I cannot run this with separators as I do with other similar scripts.

I created this action from other actions I found on the forum:  
`[#0]`  
`T=4`  
`F=_TAG`  
`1=\\s+$`  
`2=`  
`3=0`

`[#1]`  
`T=4`  
`F=_TAG`  
`1=^\\s+`  
`2=`  
`3=0`

`[#2]`  
`T=2`  
`F=_TAG`  
`1= `  
`2= `  
`3=0|0`

`[#3]`  
`T=2`  
`F=ALBUMARTIST`  
`1= / `  
`2=/`  
`3=0|0`

`[#4]`  
`T=16`  
`F=ALBUMARTIST`  
`1=/`

`[#5]`  
`T=5`  
`F=ALBUMARTIST`  
`1=$regexp(%albumartist%,(.*)',' (.*),$2 $1)`

`[#6]`  
`T=8`  
`F=ALBUMARTIST`  
`1=/`

`[#7]`  
`T=2`  
`F=ALBUMARTIST`  
`1=/`  
`2= / `  
`3=0|0`

But it will only give me one of the terms back in A B format.

Ex: lastname, firstname middlename / Miller, John Bob / Rolling Stone, The  
is converted to:  
firstname middlename lastname

---

<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:** [February 9, 2026, 12:22pm UTC](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020/34 "2026-02-09T12:22:38Z")

</div>



[Previous page](https://community.mp3tag.de/t/switching-first-and-last-name-of-artist/11020.md?page=1)
