Complicated Regex or script sought


I have an album with the following track names:

String1 Substr1.1
String1 Substr1.2
String1 Substr1.3
String2 Substr2.1
String2 Substr2.2
String3 Substr3.1

I want to change this into

String1 1. Substr1.1
String1 2. Substr1.2
String1 3. Substr1.3
String2 1. Substr2.1
String2 2. Substr2.2
String3 1. Substr3.1


So I want to number the parts of each peace. [Of course the numbers are not in the strings, so I can't use these.]

Can I do this with Regular expressions? How?

Or can someone give me a lead how to do this with scripts? Is there a tutorial for scripts?




Action type: Replace with regular expression
Field: TITLE
Regular expression: ^(.+?)\s(.+?).(\d)
Replace matches with: $1 $3. $2.$3

[ ] case-sensitive comparison


As I said: the numbers are not actually part of the strings. They are just there to show the structure of the tracks. Maybe I should have put the strings between brackets, or in quotes.

So you example won't work.

Thanks anyway.


As far as I know it is not possible in action directly, because there is no counter function in there.
But you can do it in a roundabout way in my opinion.

You can use a special placeholder %_counter% in export scripts. You can create a text file with the required new titles, then you can use that file to change the %title% fields (Textfile - Tag button).

There is a little code for an export script, but I think it is not very good:

$loop($left(%title%,$sub($strstr(%title%,' '),1)),1)$loop($left(%title%,$sub($strstr(%title%,' '),1)))$regexp(%title%,^(.+?)\s(.+?),$1 %_counter%. $2)

Must be a much better solution. I think the $left part can be replaced with $regexp in some way. But it works if the first part of your title (called StringX) doesn't contain any spaces, and the separator between StringX and SubstrX IS a space.
In the two loop part I used the $strstr function, so if the separator is not a space, you can change the parameter ' ' to the desired separator string. (In that case you have to change the $regexp parameter, too).

It works in these examples:

Titles in files:

ABBA Cats and Mice
Beatles Elephant
Beatles Sharks and Whales

The result:

ABBA 1. Dog
ABBA 2. Cats and Mice
Beatles 1. Elephant
Beatles 2. Sharks and Whales

Anyway, I wonder the regexp version of this script. :slight_smile:

Help.mte (172 Bytes)


That's what I was afraid of.

Forget it! I think indeed the best bet is to write an external file, edit it and read it back.
Awk could do the job well, I guess. In fact I would need a function that can find the largest initial substring of two strings. No idea if any language has this. Would be nice if the mp3tag script could call awk.

Probably a job for a long winter night.

Still my other question: anywhere a decent tutorial for the mp3tag scripting language? Or a couple of representative examples? Is it (like) any existing language? (Although most of these scripting languages are kind of similar).

B.t.w. I think mp3tag is terrific! Unique in its kind. No other tag editor has regexp's! (At least I haven't been able to find one and I looked for a long time before I stumbled onto mp3tag.) I am using it a lot.