# AlbumArtistSort and ArtistSort - switch first and last names

**URL:** https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992
**Category:** Mac
**Created:** [January 22, 2022, 5:10am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992 "2022-01-22T05:10:22Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 22, 2022, 5:10am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/1 "2022-01-22T05:10:22Z")

</div>

Hi,

I have recently started converting my actions from Windows to Mac, and have discovered the actions I use for the sort fields only work partially. The source format copies, but the regex replace for swapping first and last names does not.

 ![image](https://community.mp3tag.de/uploads/default/original/2X/3/3639250d20e64f2997571fa3e2ffbbf793e78f74.png)

---

<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: [January 22, 2022, 8:32am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/2 "2022-01-22T08:32:26Z")

</div>

Please see the [documentation on Mac's action to replace with regular expression](https://community.mp3tag.de/t/quick-actions-and-action-groups/51882)  
This shows that a different syntax from the WIndows version is used.

On the other hand: why do you need to swap as I bet that this field is really only used for sorting but the player then shows the contents of the non-sort field.  
And that would mean that you don't need the swap but you only have to remove the first part of the name (or the "the"). I doubt that you really need the full name for sorting.  
And this leads to the next advice: why use complicated and apparently incomprehensible expressions if the purpose does not require it. Keep it as simple as possible, would be my motto.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [January 22, 2022, 8:44am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/3 "2022-01-22T08:44:52Z")

</div>

Please also identify the expression that doesn't work as expected and post it as a textual representation using copy&paste.

Probably only very few people on earth can spot what's wrong there by just having a hard look on it 😃

---

<div class="post-metadata">

### Author: ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)
#### Post date: [January 22, 2022, 8:54am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/4 "2022-01-22T08:54:20Z")

</div>

Try switching the second and third rule.

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 23, 2022, 8:57pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/5 "2022-01-23T20:57:12Z")

</div>

> [@ohrenkino](#):
>
> On the other hand: why do you need to swap as I bet that this field is really only used for sorting but the player then shows the contents of the non-sort field.

I use the sort fields to sort by `LastName, FirstName` as Music.app and iTunes default sorting is `FirstName LastName`

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 23, 2022, 8:58pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/6 "2022-01-23T20:58:42Z")

</div>

This is taken from the Windows action, which I basically just retyped by hand in Mp3Tag for Mac.

```auto
[#0]
T=5
1=%album%
F=ALBUMSORT

[#1]
T=7
F=%albumsort%
1=%albumsort% {%dummy%}

[#2]
T=7
F=%albumsort%
1=%albumsort% (%dummy%)

[#3]
T=4
F=ALBUMSORT
1=^The (.+)
2=$1, The
3=0

[#4]
T=5
1=%albumartist%
F=ALBUMARTISTSORT

[#5]
T=4
F=ALBUMARTISTSORT
1=^The (.+)
2=$1, The
3=0

[#6]
T=4
F=ALBUMARTISTSORT
1=^\\s+|\\s+$
2=
3=0

[#7]
T=4
F=ALBUMARTISTSORT
1=\\s{2,}
2= 
3=0

[#8]
T=2
F=ALBUMARTISTSORT
1=[ 
2=[
3=0|0

[#9]
T=2
F=ALBUMARTISTSORT
1= ]
2=]
3=0|0

[#10]
T=5
1=$regexp(%albumartistsort%,'\\sfeat.?\\s',';')
F=ALBUMARTISTSORT

[#11]
T=5
1=$regexp(%albumartistsort%,'\\svs.?\\s',';')
F=ALBUMARTISTSORT

[#12]
T=5
1=$regexp(%albumartistsort%,'\\swith?\\s',';')
F=ALBUMARTISTSORT

[#13]
T=5
1=$regexp(%albumartistsort%,'\\sand?\\s',';')
F=ALBUMARTISTSORT

[#14]
T=16
F=ALBUMARTISTSORT
1=;

[#15]
T=16
F=ALBUMARTISTSORT
1=,

[#16]
T=16
F=ALBUMARTISTSORT
1=&

[#17]
T=4
F=ALBUMARTISTSORT
1=^([^,[]+)\\s([^,[]+)$
2=$2, $1
3=0

[#18]
T=4
F=ALBUMARTISTSORT
1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
2=$2, $1 $3
3=0

[#19]
T=8
F=ALBUMARTISTSORT
1=; 

[#20]
T=2
F=ALBUMARTISTSORT
1=Artists, 
2=
3=0|0

[#21]
T=5
1=%artist%
F=ARTISTSORT

[#22]
T=4
F=ARTISTSORT
1=^The (.+)
2=$1, The
3=0

[#23]
T=4
F=ARTISTSORT
1=^\\s+|\\s+$
2=
3=0

[#24]
T=4
F=ARTISTSORT
1=\\s{2,}
2= 
3=0

[#25]
T=2
F=ARTISTSORT
1=[ 
2=[
3=0|0

[#26]
T=2
F=ARTISTSORT
1= ]
2=]
3=0|0

[#27]
T=5
1=$regexp(%artistsort%,'\\sand?\\s',';')
F=ARTISTSORT

[#28]
T=5
1=$regexp(%artistsort%,'\\svs.?\\s',';')
F=ARTISTSORT

[#29]
T=5
1=$regexp(%artistsort%,'\\swith?\\s',';')
F=ARTISTSORT

[#30]
T=5
1=$regexp(%artistsort%,'\\sfeat.?\\s','; ')
F=ARTISTSORT

[#31]
T=16
F=ARTISTSORT
1=;

[#32]
T=16
F=ARTISTSORT
1=,

[#33]
T=16
F=ARTISTSORT
1=&

[#34]
T=4
F=ARTISTSORT
1=^([^,[]+)\\s([^,[]+)$
2=$2, $1
3=0

[#35]
T=4
F=ARTISTSORT
1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
2=$2, $1 $3
3=0

[#36]
T=8
F=ARTISTSORT
1=; 

[#37]
T=5
1=%title%
F=TITLESORT

[#38]
T=4
F=TITLESORT
1=^The (.+)
2=$1, The
3=0

[#39]
T=7
F=%titlesort%
1=%titlesort% (%dummy%)

[#40]
T=7
F=%titlesort%
1=%titlesort% {%dummy%}

[#41]
T=5
1=%composer%
F=COMPOSERSORT

[#42]
T=4
F=COMPOSERSORT
1=^\\s+|\\s+$
2=
3=0

[#43]
T=4
F=COMPOSERSORT
1=\\s{2,}
2= 
3=0

[#44]
T=2
F=COMPOSERSORT
1=[ 
2=[
3=0|0

[#45]
T=2
F=COMPOSERSORT
1= ]
2=]
3=0|0

[#46]
T=16
F=COMPOSERSORT
1=,

[#47]
T=16
F=COMPOSERSORT
1=;

[#48]
T=16
F=COMPOSERSORT
1=&

[#49]
T=4
F=COMPOSERSORT
1=^The (.+)
2=$1, The
3=0

[#50]
T=4
F=COMPOSERSORT
1=^([^,[]+)\\s([^,[]+)$
2=$2, $1
3=0

[#51]
T=4
F=COMPOSERSORT
1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
2=$2, $1 $3
3=0

[#52]
T=8
F=COMPOSERSORT
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: [January 23, 2022, 9:07pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/7 "2022-01-23T21:07:37Z")

</div>

> [@djdizzle](#):
>
> I use the sort fields to sort by `LastName, FirstName`

That is understood.  
What I would like to emphasize: If you have "Beatles" and "The Beatles" where the latter is switches to "Beatles, The" it actually does not matter that there was the "The" - you can simply leave that out.

If you have Katie Melua, then you don't need the "Katie" part as "Melua" is more or less unique. And this will apply to most other artists.  
So the action could be much, much simpler as you only have to delete the first word and there you are: you have the term by which the track gets adequately sorted.

The other problem that I usually see: why have this extra effort at all?  
There are so many names where you would not swap the first and last part. "Uriah Heep" would never be sought under "Heep", I guess. What about "Rolling Stones"? "New Kids on the Block"?  
So you would have to define a lot of exceptions where the name should be swapped and where it shouldn't.  
So my opinion (and you are entitled just as much to have your's) is: swapping is pointless.

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 24, 2022, 6:04am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/8 "2022-01-24T06:04:08Z")

</div>

> [@ohrenkino](#):
>
> What about "Rolling Stones"? "New Kids on the Block"?

Those particular instances are processed under an action specifically for groups.

---

<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: [January 24, 2022, 7:17am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/9 "2022-01-24T07:17:26Z")

</div>

Yes, sure they would have to.  
The way you currently treat the names, this is mandatory.  
My point was: is that necessary at all as the swapping does not make searching easier.  
Some artist names are left as they are - so you can type them in the search as you speak them,  
others have been swapped and there you have to type in the formerly second name.  
IMHO this makes the whole thing more complicated.  
Just another example sprang to mind: Frida Gold. Looks like a person's name but is a group in fact. Nobody in that group is called Frida. So, would that get treatment as a name to swapped or kept? And how to know the difference to "Gordon Lightfoot"?

OK, you will probably keep your workflow and sorting rules.

There is still a request to be anwered:

> [@Florian](#):
>
> Please also identify the expression that doesn't work

I don't know whether you realized that

> [@djdizzle](#):
>
> taken from the Windows action, which I basically just retyped by hand in Mp3Tag for Mac

is probably not the best approach if you have a look at the

> [@ohrenkino](#):
>
> [documentation on Mac's action to replace with regular expression](https://community.mp3tag.de/t/quick-actions-and-action-groups/51882)

which says that the syntax is a little different from the Windows version.

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 24, 2022, 10:04pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/10 "2022-01-24T22:04:34Z")

</div>

> [@Florian](#):
>
> Please also identify the expression that doesn't work as expected and post it as a textual representation using copy&paste.

```auto
[#17]
T=4
F=ALBUMARTISTSORT
1=^([^,[]+)\\s([^,[]+)$
2=$2, $1
3=0

```

```auto
[#18]
T=4
F=ALBUMARTISTSORT
1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
2=$2, $1 $3
3=0

```

```auto
[#34]
T=4
F=ARTISTSORT
1=^([^,[]+)\\s([^,[]+)$
2=$2, $1
3=0

```

```auto
[#35]
T=4
F=ARTISTSORT
1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
2=$2, $1 $3
3=0

```

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 24, 2022, 10:06pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/11 "2022-01-24T22:06:38Z")

</div>

> [@ohrenkino](#):
>
> Please see the [documentation on Mac's action to replace with regular expression](https://community.mp3tag.de/t/quick-actions-and-action-groups/51882)  
> This shows that a different syntax from the WIndows version is used.

I'll check out the documentation

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [January 24, 2022, 10:12pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/12 "2022-01-24T22:12:06Z")

</div>

Lets focus on actions #17 and #18 which cover `ALBUMARTISTSORT`. What do you expect them to do and can you post an example where it fails?

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 25, 2022, 12:28am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/13 "2022-01-25T00:28:39Z")

</div>

> [@djdizzle](#):
>
> ```auto
> [#17]
> T=4
> F=ALBUMARTISTSORT
> 1=^([^,[]+)\\s([^,[]+)$
> 2=$2, $1
> 3=0
> 
> ```

I believe should be the one which swaps `FirstName LastName` to `LastName, FirstName`

> [@djdizzle](#):
>
> ```auto
> [#18]
> T=4
> F=ALBUMARTISTSORT
> 1=^([^,[]+)\\s([^,[]+)\\s(\\[.+\\])$
> 2=$2, $1 $3
> 3=0
> 
> ```

I am pretty sure should cover when an artist has `FirstName SecondName LastName` to `LastName, FirstName SecondName`

eg. `3OH!3 feat. Katy Perry` is only being changed to `3OH!3; Katy Perry`, and not `3OH!3; Perry, Katy`

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [January 25, 2022, 7:56am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/14 "2022-01-25T07:56:54Z")

</div>

I had a look at the expression used in #17 and it seems to me that an escape of the opening bracket in the first match group is missing. A correct expression would be

`^([^,\[]+)\s([^,\[]+)$`

The same applies to the expression using in #18

`^([^,\[]+)\s([^,\[]+)\s(\[.+\])$`

---

<div class="post-metadata">

### Author: ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)
#### Post date: [January 25, 2022, 11:12am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/15 "2022-01-25T11:12:21Z")

</div>

#18 is simply a special case of #17 that handles parts in square brackets which shall remain at the end. They could be combined into a single action:

```auto
[#17]
T=4
F=ALBUMARTISTSORT
1=^([^,\\[]+)\\s([^,\\[]+)(\\s\\[.+\\])?$
2=$2, $1$3
3=0

```

- in: John Doe [DJ]
- out: Doe, John [DJ]

---

<div class="post-metadata">

### Author: ![Crissov](https://community.mp3tag.de/user_avatar/community.mp3tag.de/crissov/32/6619_2.png) [@Crissov](https://community.mp3tag.de/u/Crissov)
#### Post date: [January 25, 2022, 11:33am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/16 "2022-01-25T11:33:19Z")

</div>

- #6 is a less performant RX for `$trim(%albumartistsort%)`
- #10 through #13 can be combined in a single expression, also fixing some typos (#15 and #16 could also be included):

```auto
[#10]
T=5
1=$regexp(%albumartistsort%,'\\s(feat\\.?|vs\\.?|with|and)\\s',';')
F=ALBUMARTISTSORT

```

---

<div class="post-metadata">

### Author: ![djdizzle](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/ed8c4c/32.png) [@djdizzle](https://community.mp3tag.de/u/djdizzle)
#### Post date: [January 26, 2022, 10:29pm UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/17 "2022-01-26T22:29:21Z")

</div>

This worked, thanks. I mustn't have realised I missed the escape charaters when I initially did it... it was very late at night.

Also, is there a way in the sort fields to replace charatcters with graves, acutes, tildes, etc. with regular characters?

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [January 27, 2022, 6:06am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/18 "2022-01-27T06:06:09Z")

</div>

> [@djdizzle](#):
>
> Also, is there a way in the sort fields to replace charatcters with graves, acutes, tildes, etc. with regular characters?

Yes, please open a new topic on, well, a new topic.

---

<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 26, 2022, 6:06am UTC](https://community.mp3tag.de/t/albumartistsort-and-artistsort-switch-first-and-last-names/55992/19 "2022-02-26T06:06:29Z")

</div>

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