Need help with regex for ARTISTSORT

Hello,

: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 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!

Action type: Replace with regular expression
Field: ARTISTSORT
Regular expression: \s*([^,]+)\s([^,]+)(,|$)
Replace matches with: $2, $1;

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!