I’m trying to make a tagger script that checks if the artist’s name starts with an article (The, A, or An) and delete the artistsort field if it’s not there. I tried to simplify it as much as possible, and I can’t figure out why this is not working:
$if($rsearch(%artist%,[Tt][Hh][Ee] |[Aa] |[Aa][Nn] ),$delete(artistsort))
According to the docs, $if(x,y,[else]) is supposed to return else if the value in x is empty, so it will not go through with y. $rsearch is supposed to return an empty string if the search comes up empty. The artistsort field is still showing up for artist names that don’t start with an article. What am I doing wrong?
1 Like
The problem is that you are triggering the $delete() on a match rather than no match. Try adding another comma before $delete(artistsort) so that there is an empty y (return if true) field in the $if() statement.
Something like:
$if($rsearch($lower(%artist%),^\(the|an?\) ),,$delete(artistsort))
4 Likes
Ah, you’re right. It was late when I made the post and I must have been tired, it seems so obvious now. In the meantime I solved it myself by adding the $not() function between the $if and $rsearch statements. I also improved the regex a little bit like this:
$if($not($rsearch(%artist%,\\A[Tt][Hh][Ee] |\\A[Aa] |\\A[Aa][Nn] ),$delete(artistsort))
The \A matches string at the beginning of the artist name, so it won’t sort an artist with ‘the’ in the middle of their name.
I’m working on a more complex version of the script that also matches classical music and a few other exceptions to include the artistsort tag. This is more my personal preference but I wonder if it’d be useful to others.
1 Like