Help with conditional format of filename from tag field

I admit, regex's give me a headache even though I try now and then. Anyway, I read through most of the posts and can't really find any analog to what I want to do. Basically, I want to reformat the filename of a song from Tags as follows:

%artist% - %title% - %disknumber%

BUT, I only want the "- %disknumber%" to appear if %disknumber% is not empty. If %disknumber% is empty the filename should display as:

My Artist - Song Title

with no trailing " - "

But if disknumber contains something like SC001 then it should appear as:

My Artist - Song Title - MyDiskNumber

Hope that's clear. Thanks for the help!

The official discnumber tag is with a c

Anyway, does this do what you want?
%artist% - %title%[ - %disknumber%]

Actually, yes it does. I found that feature buried in the HELP not more than 1/2 hour after I posted my question.

OK but now I'm puzzled. I'd like to have this sort of thing be an Action that I can apply it quickly rather than go through the Tag -> Filename convert thing and then pull it the history from the dropdown.

So I've tried both the Format Action using _FILENAME as the source and that string as the Format AND I've tried the REPLACE Action.

Both give me the same result on testing. 1 of 1 tag formatted, 0 of 1 files renamed. What am I doing wrong?

It should work with a Format value action.

Action type: Format value
Format string: %artist% - %title%[ - %disknumber%]

Maybe the file had already the right file name?

Try adding this to [Tag > Filename]

[-ARTIST/Disk/Album/Track/Title/Albumartist - ]$replace($replace($replace($replace($replace($left($if((%artist%%albumartist%),$if($eql(%artist%,%albumartist%),$replace(%albumartist%,-,$char(8211)) - ,$if(%artist%,$replace(%artist%,-,$char(8211)) - ,$if(%albumartist%,.$replace(%albumartist%,-,$char(8211)) - ,))),<!Unknown! - >)[ - Artist - ][ - Disk - ]$if(%discnumber%,D$num(%discnumber%,) - ,)[ - Disk - ][ - Album - ]$if(%album%,$replace(%album%,-,$char(8211)) - ,)[ - Album - ][ - Track - ]$if(%track%,$num(%track%,2) - ,)[Track][ - Title - ]$if((%artist%%albumartist%),$if($eql(%artist%,%albumartist%),$if(%title%,$replace(%title%,-,$char(8211)),notitle),[----]$if(%artist%,$if(%albumartist%,$if(%title%,$replace(%title%,-,$char(8211)),notitle) $char(8226) %albumartist%,$if(%title%,$replace(%title%,-,$char(8211)),notitle)),$if(%title%,$replace(%title%,-,$char(8211)),notitle))[----]),$if(%title%,$replace(%title%,-,$char(8211)),notitle))[ - Title - ],179),/,;),*,$char(164)),&,&),:,; ),",'''')

i could shorten above and remove [some stuff between these] to trim it down but i'm to lazy once i had what i wanted i left it alone.