TITLE tag has "Artist - Title"

Hi everyone, I've been using mp3tag for a few months now continuously rebuilding my music collection.
I write my own scripts and have dozens of them that do everything I need in my own way (I'm very picky).
I've read different forum topics, external sources, and the FAQ, but I can't solve this issue.

I often run into certain problems when ID-tags are not in their correct fields.
Like, when the TITLE field has everything "ARTIST - TITLE", leaving the ARTIST field empty.

I always try writing my scripts to solve anything, even if it takes half an hour.
So far this is my script, I would appreciate any help:

I'm using Guess Values:
Source Format:
$regexp(%title%~%artist%,(\b.?\b)(.?-.?)(\b.?)~(.*?),$if($len(%artist%)=0,($3~$1),(%title%~%artist%)))
Guessing Pattern:
%title%~%artist%

I realize it is probably a bit messy code now, I'm not even sure if I'm using the $len function properly. Like, do I use == or =.
I don't know how to determine if the ARTIST field is empty. because if it's not, and the TITLE already has a colon then I'm screwed.

Hope someone can help, thanks in advance! :slight_smile:

OK, I figured it out, less complex than I expected.
In case someone finds it useful, here it is... :

$regexp(%title%~%artist%,(.?)(\s-\s*)(.?)~(.?),$iflonger(%artist%,0,%title%~$4,$3~$1)

MAYBE if someone reads it, I wonder why "%title%~$4" works but "%title%~%artist%" simply duplicates teh Artist field (like "FanuFanu") :unsure:

how to determine if the ARTIST field is empty

$if(%artist%,not empty,empty)

Oh that's quite straightforward, thank you.

(this works now)
$regexp(%title%~%artist%,(.?)(\s-\s*)(.?)~(.?),$iflonger(%artist%,0,%title%~$4,$3~$1))