# Complicated Regex or script sought

**URL:** https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957
**Category:** Support
**Created:** [June 21, 2008, 10:55am UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957 "2008-06-21T10:55:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RabanePaco](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RabanePaco](https://community.mp3tag.de/u/RabanePaco)
#### Post date: [June 21, 2008, 10:55am UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/1 "2008-06-21T10:55:37Z")

</div>

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  
etc.

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

etc.

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?

Thanks!

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [June 23, 2008, 7:58am UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/2 "2008-06-23T07:58:37Z")

</div>

Try

_Action type:_ **Replace with regular expression**  
_Field:_ **TITLE**  
_Regular expression:_ **^(.+?)\s(.+?).(\d)**  
_Replace matches with:_ **$1 $3. $2.$3**

[] case-sensitive comparison

---

<div class="post-metadata">

### Author: ![RabanePaco](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RabanePaco](https://community.mp3tag.de/u/RabanePaco)
#### Post date: [June 23, 2008, 7:33pm UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/3 "2008-06-23T19:33:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Stevest](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/a698b9/32.png) [@Stevest](https://community.mp3tag.de/u/Stevest)
#### Post date: [June 24, 2008, 10:23am UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/4 "2008-06-24T10:23:44Z")

</div>

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)
$loopend()$loopend()

```

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 Dog
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. 🙂

[Help.mte](https://community.mp3tag.de/uploads/default/original/2X/7/70c60a4bcff88b1eb53611005a65f586b14fc39d.mte) (172 Bytes)

---

<div class="post-metadata">

### Author: ![RabanePaco](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@RabanePaco](https://community.mp3tag.de/u/RabanePaco)
#### Post date: [June 25, 2008, 12:25pm UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/5 "2008-06-25T12:25:26Z")

</div>

> [@Stevest](#):
>
> As far as I know it is not possible in action directly, because there is no counter function in there.  
> [...] 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).

That's what I was afraid of.

> [@](#):
>
> If the first part of your title doesn't contain any spaces

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.

Thanks.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [February 9, 2026, 12:21pm UTC](https://community.mp3tag.de/t/complicated-regex-or-script-sought/6957/6 "2026-02-09T12:21:01Z")

</div>


