# Add space to, swap Lastname,Firstname

**URL:** https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483
**Category:** Support
**Created:** [June 22, 2006, 9:23pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483 "2006-06-22T21:23:14Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tinana](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@tinana](https://community.mp3tag.de/u/tinana)
#### Post date: [June 22, 2006, 9:23pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/1 "2006-06-22T21:23:14Z")

</div>

Hi,

In the artist field, when the artists name is in the form "lastname,firstname" , how do I....

-separate the two names/add a space  
-remove the comma and  
-swap the last and first names?

Thank-you in advance if anyone can be of help.

---

<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: [June 23, 2006, 2:26am UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/2 "2006-06-23T02:26:52Z")

</div>

> [@tineg](#):
>
> Hi,  
> In the artist field, when the artists name is in the form "lastname,firstname" , how do I....  
> -separate the two names/add a space  
> -remove the comma and  
> -swap the last and first names?  
> Thank-you in advance if anyone can be of help.

If you have a field: lastname,firstname  
or something like this: lastname , firstname  
and want it to be: firstname lastname  
you may create an Action with the following properties:  
Field: your\_fieldname  
Regular Expression: `(.*),(.*)`  
Replace matches with: `$trim($2) $trim($1)`  
DD.20060623.0625

---

<div class="post-metadata">

### Author: ![tinana](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/2acd7d/32.png) [@tinana](https://community.mp3tag.de/u/tinana)
#### Post date: [June 23, 2006, 9:23pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/3 "2006-06-23T21:23:04Z")

</div>

Thanks DetlevD...I gave that a try first thing this morning before heading out to work this morning and I couldn't be happier.

Thanks again.

---

<div class="post-metadata">

### Author: ![neocobe](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@neocobe](https://community.mp3tag.de/u/neocobe)
#### Post date: [May 30, 2013, 6:40am UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/4 "2013-05-30T06:40:18Z")

</div>

Briliant!

Was looking for This!!

A+

---

<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: [May 25, 2024, 11:37am UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/5 "2024-05-25T11:37:45Z")

</div>

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").

---

<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: [May 25, 2024, 12:11pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/6 "2024-05-25T12:11:11Z")

</div>

> [@josephzitt](#):
>
> Before I reinvent the wheel

Yes, that wheel has been invented a long time ago,  
See the HowTos:

> [@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: ![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: [May 25, 2024, 3:12pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/7 "2024-05-25T15:12:38Z")

</div>

I use this action to perform this for albumartist values:  
Replace with regular expression:  
Field:

```auto
ALBUMARTIST

```

Regular expression:

```auto
([^;]+\s?[^;]+(?:\s?[^;]+)?)\s(?!Duo|Trio|Quartet|Quartetto|Quintet|Sextet|Sixtet|Sestetto|Septet|Octet|Ottetto|Nonet|Orchestra|Chamber Orchestra|Ensemble)([^;]+)

```

Replace matches with:  
$2, $1

It's more wordy because it also works on multiple albumartist values delimited by ";". And I added a few obvious things that should be avoided like trying to swap quartet, duo, trio etc. names.  
It's not perfect but

> [@josephzitt](#):
>
> realize that I would have to look at the contents before doing it to avoid messing up "Jethro Tull"

as long as you're careful, it works pretty well for me.

 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/a/0/a05d52547092b1818a8f2dafe72af8532b4c0a95.png)  
Here's an example usage that also shows a limitation of my action. The skipping of duo, trio etc. only works if the albumartist only consists of 2 words. If it has 3, the 3rd one is skipped but the first 2 are still swapped. See "Cologne Saxophone Quartet" which becomes "Saxophone, Cologne Quartet".  
This action works both for values separated by ";" and for real multi values "//".

I hope it gives you some ideas. 🙂

---

<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: [May 25, 2024, 3:27pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/8 "2024-05-25T15:27:45Z")

</div>

See also this discussion whether it really makes sense to swap at all:

> [@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/2):
>
> Didn't you participate in a thread that deals more or less with the problem of lists with a slash in them? And to be honest: the swapping of names ... does it really make sense? There are so many exceptions that the swapped names in the end do not ease the access to the artist. Any decent player will search for artist name parts so it does not matter which structure the name has. In which field do you want to swap the names? I hope, only in the ~SORT fields as otherwise it will become a str…

and if it is really necessary "because of reasons", consider the use of the ~SORT fields (ARTISTSORT, TITLESORT etc.).

---

<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: [June 24, 2024, 3:27pm UTC](https://community.mp3tag.de/t/add-space-to-swap-lastname-firstname/3483/9 "2024-06-24T15:27:57Z")

</div>

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