An action to re-order text?

I am trying to format my classical music. So in the title field I want to move the Op. number to the beginning.

So for example the track title might be:

Piano Sonata No. 2 in B-flat minor Op. 35 "Funeral March" - 2. Scherzo

I want it to be:

Op. 35 - Piano Sonata No. 2 in B-flat minor "Funeral March" - 2. Scherzo

Of course the Op. number isn't always going to be the same.

I tried to create an action myself for this, but it's too difficult.

Any help would be appreciated, Thanks!

If the "Op." is the separator and always followed by a number, you can try an action of the type
"Replace with regular expression" for TITLE
Search: (.) Op. (\d+) (.)
Replace: Op. $2 $1 $3

Action: Format value
Field: TITLE
Formatstring: $regexp(%TITLE%,'^(.+?)\b(?:op.?|opus)\s?(\d+),?\s?(.+?)$','Op. $2 - $1$3',1)

From: aaa op123 bbb aaa op 123 bbb aaa op.123 bbb aaa op. 123 bbb aaa opus123 bbb aaa opus 123 bbb To: Op. 123 - aaa bbb


Brilliant! Thanks!

I have noticed one flaw: if the Op. number is at the end of the title it will only take the first digit.

So "Op. 23" is moved as "Op. 2" and "3" stays at the end.

I added an action to the group that adds text to the title before running your action & then removes it after running, which solves it.

That's another starting point, but you can build quickly the new regular expression, which works also without the last part " bbb".

Action: Format value
Field: TITLE
Formatstring: $regexp(%TITLE%,'^(.+?)?\s?(?:op.?|opus)\s?(\d+),?\s?(.+?)?$','Op. $2 - $1$3',1)