# Need help with regex for ARTISTSORT

**URL:** https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653
**Category:** Support
**Created:** [November 1, 2011, 11:20pm UTC](https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653 "2011-11-01T23:20:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![paulgj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/b5e925/32.png) [@paulgj](https://community.mp3tag.de/u/paulgj)
#### Post date: [November 1, 2011, 11:20pm UTC](https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653/1 "2011-11-01T23:20:44Z")

</div>

Hello,

![:book:](https://community.mp3tag.de/uploads/default/original/1X/0036d5b68f6226c53f6c68abfd0a7b8096fd4505.gif ":book:") I have been studying regex syntax today like crazy but cannot figure this one out...

I have my ARTIST tags in the following format:

ArtistFirstName ArtistLastName, AdditionalArtistFirstName AdditionalArtistLastName, etc

I want to create the ARTISTSORT tag with the value as follows:

ArtistLastName, ArtistFirstName; AdditionalArtistLastName, AdditionalArtistFirstName; etc

Typically the ARTIST tag will contain only a single name, but often I have multiple names so ideally the conversion should be able to handle both cases.

Based on this thread [Multiple value artist tag to multiple value artistsort](https://community.mp3tag.de/t/12599/1) I have copied the %artist% tag into the ARTISTSORT tag but am not getting correct results with the replace with regex action.

Any help would be appreciated.

Thanks!

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [November 2, 2011, 6:46am UTC](https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653/2 "2011-11-02T06:46:07Z")

</div>

_Action type:_ **Replace with regular expression**  
_Field:_ **ARTISTSORT**  
_Regular expression:_ **\s\*([^,]+)\s([^,]+)(,|$)**  
_Replace matches with:_ **$2, $1;**

---

<div class="post-metadata">

### Author: ![paulgj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/b5e925/32.png) [@paulgj](https://community.mp3tag.de/u/paulgj)
#### Post date: [November 2, 2011, 5:42pm UTC](https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653/3 "2011-11-02T17:42:42Z")

</div>

Thanks Dano, that works great. How did you figure out what regex to use?

Also I added another action to remove the trailing semi-colon but it is not working, thanks for any corections as I'm still a regex newbie.

_Action type_: **Replace with regular expression**  
_Field_: **ARTISTSORT**  
_Regular expression_: **^(.\*);$**  
_Replace matches with_: **$1**

OK, even this doesn't work in place of the above

_Action type_: **Format value**  
_Field_: **ARTISTSORT**  
_Format string_: **$trimRight(%artistsort%,';')**

Weird!

---

<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:23pm UTC](https://community.mp3tag.de/t/need-help-with-regex-for-artistsort/12653/4 "2026-02-09T12:23:25Z")

</div>


