Action to remove COMPOSER from TITLE field

I have a lot of songs where the Title field start with the composer, e.g.
Mozart: La Traviata, Act 1 ...
And I want to remove Mozart (and the : and space, but I assume I can easily remove these with a separate action, examples are on the forum/help file. I cannot use RE because the composer is not always followed by a : , and sometimes a : is used elsewhere in the title.
I also only want to remove the composer when it is in the beginning of the title, not elsewhere.

The easy way to e.g. remove "The" in front of title would be : ^The\s+
So I tried an action with :
Field : TITLE
Regular expression : ^%composer%:\s
But this did not work ...

Any suggestions ?
Thanks !

You cannot reference field names in a regular expression.

A suggestion would be for a "Format value" action for TITLE (with 'Mozart: La Traviata: Act 1'):
$regexp(%title%,.?: (.),$1)

The ? makes the expression less gready.

Convert "Tag - Tag"
... or ...
Action "Format value"
Field: TITLE
Formatstring: $replace('^'%TITLE%,'^'%ARTIST%': ',)

DD.20170115.1613.CET

If the OP wants to replace the composer, shouldn't it be
Formatstring: $replace('^'%TITLE%,'^'%composer%': ',)

Ah yes, in my testcase I have checked it with the value from ARTIST, but it also works with the value from COMPOSER.
Because of the applied function $replace, there are no wildcards to be applicable, and therefore the spelling of the composer name must be the same as in the title string.

DD.20170115.1735.CET

First of all, many thanks for your help.
It works, but if the match is not perfect, (composer and the : and one space), then a ^ is placed of the Title string (and the composer is not removed).
I tried removing the second '^' (just before %composer%), but that didn't work (and I don't really "understand" that one; the first one, before %title%, I suppose that is to indicate to only look in the beginning of the field, but the second one, no idea ...)

Anyway, let me just explain my "workflow", and please let me know if I can optimize something.

Fist step is to filter in the navigation window all songs that I want to change.
I first tried "Title HAS composer" but this didn't work. Neither did "Title HAS %Composer%".
So I found this one in a forum topic:

"$ifgreater($strstr(%title%,%composer%),0,yes,no)" IS yes

And this did the trick, but it finds the composer wherever it is placed in the Title field.
So I now use this one (not that I really understand why it does what it does, but it is an obvious copy/paste from the action):

"$ifgreater($strstr('^'%title%,'^'%composer%),0,yes,no)" IS yes

So this gives me indeed all occurrences where Composer is only in the beginning of the Title field, and not elsewhere.

Second step is then to use an action with this code:

Action "Format value"
Field: TITLE
Formatstring: $replace('^'%TITLE%,'^'%composer%,)

So I removed the ": ". I assume that this will only remove the composer, but will leave me in many cases trailing spaces or a trailing :. But these are quite easy to remove; some examples are provided in the help and in the forum, so running these twice each (to take into account all variations ("Mozart : La...", "Mozart:La...", "Mozart :La...", "Mozart:La..." ) should clean up the field.

I think this will accomplish what I want, but with quite a few steps.

Hmm, the constructed match is rather perfect, because it matches only one case.
The meaning of the additional helping character '^', at the left edge of the TITLE string and the COMPOSER string, is just giving an anchor, to match only one dedicated location for the function $replace.

You should not apply the formatstring against files, where the TITLE string does not match the specified problem.
Apply the Mp3tag Filter to get only those candidates into the list view, which matches for the given task.

See Mp3tag help for "Filter", the expression following the HAS operator must be a string constant, a tagfield name COMPOSER or tagfield content %COMPOSER% is not allowed.

Ok, this should display only those files, where the TITLE string starts with the COMPOSER string.

The following formatstring applies different combinations of space and semicolon related substrings ... with the caveat of replacing all matches within the given TITLE string:

TITLE <== $replace('#'$replace(%TITLE%,' : ',':',' :',':',': ',':'),'#'%COMPOSER%':',)

DD.21070116.1014.CET

Thanks for your help.
I think this version is a bit too powerful and "dangerous" for me ...
I prefer limiting the changes where composer is only at the beginning of TITLE.

So I will

  1. Use the filter to only select these files (as per my previous post)
  2. Use the action that you have suggested (without the : and space)
  3. I figured out that I only have to run two additional actions (Action type: Replace with regular expressions)

Fist to remove trailing spaces :
Field: TITLE
Regular expression: ^\s+
Replace matches with: //stays empty//

And then to remove the trailing ":" (and any other following spaces):
Field: TITLE
Regular expression: ^:\s+
Replace matches with: //stays empty//

Thanks again for your help.

Did you know that there is the $trim() function that removes heading and trailing spaces?
So an action group that

  1. trims a field
  2. removes all no : in the first position
  3. trims the field again

would also be possible. So many options, so little time.

Thanks for pointing that out !
I looked it up, and have seen that TrimLeft(x) does the same but only for trailing characters.

So just for completeness, to use that, is that a "Format value" action type ?

But I assume that I also can combine my two actions in a single action group, so run both together?
So with Regular Expressions I can do it with two actions, and with TrimLeft I have to use three?

Anyway, both seem to work.
As you wrote ... "so many options, so little time ..." !
Thanks !

There should be nothing dangerous, it just does what you wanted, by one formatstring, in one go, in order to ...

Note: Both examples are made for leading characters, because of the caret sign in front of the regular expression.

For this simple task, you do not need the regular expression feature, because Mp3tag offers some simple ready made functions, like $trimLeft or $trimRight or $trim, for example ...
'#'$trimRight('abc : ',' :')'#' will give '#abc#'
'#'$trimLeft(' : abc',' :')'#' will give '#abc#'
'#'$trim(' : : : : : abc: :::: ',' :')'#' will give '#abc#'

Note:
These examples can be evaluated within the Converter "Tag - Tag" [Alt+5].
This converter dialog is always helpfull to check out, how a formatstring does work.

DD.20170116.1733.CET, DD.20170116.1841.CET

With "too powerful", I referred to your comment that it will replace all matches within the TITLE string, and I only want to cover the case that the composer is in the beginning of TITLE.

When I am looking at this command :
'#'$trimLeft(' : abc',' :')'#' will give '#abc#'
I don't really understand it.... (the # ? ; the : in the first argument ?)
I assume I have to create an action with Format Value action type?
e.g.
$trimleft(%TITLE%,':')

And to be precise, I would have to use what exactly? I just don't understand the syntax on how to cover in one expression all the cases (" : abc", "abc", " abc", ":abc", " :abc" ; and this are just the combination of one space and : , not the case that there are multiple spaces). With the regular expressions, it seems to cover all cases with just two commands, so not very extensive...

Anyway, I don't want to use too much of your time ... I have a solution (with RE) that works.
However, it would of course teach me (and others reading this forum) more details about the syntax and usage of the trim function...

My comment was just related to the $replace function and the matching of particular string sequences build of space and colon characters.

These are examples to demonstrate how it works.
Try this out within the Converter "Tag - Tag", there is a preview of the result.

The function $replace allows multiple pairs of search and replace items.
Sometimes it will be easier to apply $replace than $regexp, especially for beginners.

DD.20170116.1859.CET