# Track numbers from malformed filenames

**URL:** https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651
**Category:** Support
**Created:** [July 17, 2012, 2:35pm UTC](https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651 "2012-07-17T14:35:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![w2irt](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/7ea924/32.png) [@w2irt](https://community.mp3tag.de/u/w2irt)
#### Post date: [July 17, 2012, 2:35pm UTC](https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651/1 "2012-07-17T14:35:49Z")

</div>

Hi folks,  
I'm trying to organize a fairly large library who's filename structure is constant but badly constructed. When the songs were ripped from source a leading dash (-) between the title and track number was omitted, but a space-dash-space ( - ) was added _after_ the track number. Thus:

**The Who - Won't Get Fooled Again 005 - .mp3**  
instead of  
**The Who - Won't Get Fooled Again - 005.mp3**

What I'm trying to accomplish is to extract the track number from the filename and move it into the TRACK # field, leaving the actual filename to read:  
**The Who - Won't Get Fooled Again.mp3**

Thanks in advance!

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [July 17, 2012, 3:06pm UTC](https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651/2 "2012-07-17T15:06:03Z")

</div>

> [@w2irt](#):
>
> ... When the songs were ripped from source a leading dash (-) between the title and track number was omitted, but a space-dash-space ( - ) was added _after_ the track number. Thus:  
> **The Who - Won't Get Fooled Again 005 - .mp3**  
> instead of  
> **The Who - Won't Get Fooled Again - 005.mp3**  
> What I'm trying to accomplish is to extract the track number from the filename and move it into the TRACK # field, leaving the actual filename to read:  
> **The Who - Won't Get Fooled Again.mp3**  
> Thanks in advance!

As always ... Mp3tag provides several ways to reach the goal ...  
here is one way ... using the converter "Tag - Tag" ...

Step 1:

 

**Convert** | **Tag - Tag** | **ALT+5**

 

_Select format string_

 

Field: **TRACK**

 

Format string: **$regexp(%\_filename%,'^(.+?)\s0\*(\d+)\s.+?$','$2')**

 

Preview: **5**

 

Step 2:

 

**Convert** | **Tag - Tag** | **ALT+5**

 

_Select format string_

 

Field: **\_FILENAME**

 

Format string: **$regexp(%\_filename%,'^(.+?)\s0\*(\d+)\s.+?$','$1')**

 

Preview: **The Who - Won't Get Fooled Again**

 

... or ...

Step 1:

 

**Convert** | **Tag - Tag** | **ALT+5**

 

_Select format string_

 

Field: **TRACK**

 

Format string: **$num($cutLeft($trimRight(%\_filename%,' -'),$strrchr($trimRight(%\_filename%,' -'),' ')),1)**  
... or ...  
Format string: **$num($reverse($num($trimLeft($reverse(%\_filename%),' -'),1)),1)**

 

Preview: **5**

 

Step 2:

 

**Convert** | **Tag - Tag** | **ALT+5**

 

_Select format string_

 

Field: **\_FILENAME**

 

Format string: **$trimRight(%\_filename%,' -0123456789')**

 

Preview: **The Who - Won't Get Fooled Again**

 

... or using a group of actions ...

Begin Action Group **Test\_2012#20120717.w2irt.Guess** 

Action #1  
_Actiontype 7:_ **Import tag fields (guess values)**  
_Source format \_\_:_ **$reverse(%\_filename%)**  
_Guessing pattern:_ **%DUMMY% - %TRACK% %TITLE% - %ARTIST%**

 

Action #2  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TRACK**  
_Formatstring:_ **$num($reverse(%TRACK%),1)**

 

Action #3  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **TITLE**  
_Formatstring:_ **$reverse(%TITLE%)**

 

Action #4  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **ARTIST**  
_Formatstring:_ **$reverse(%ARTIST%)**

 

Action #5  
_Actiontype 5:_ **Format value**  
_Field \_\_\_\_\_\_:_ **\_FILENAME**  
[i]Formatstring: **%ARTIST%' - '%TITLE%' - '$num(%TRACK%,3)**

 

End Action Group **Test\_2012#20120717.w2irt.Guess** (5 Actions)

 

DD.20120717.2007.CEST

---

<div class="post-metadata">

### Author: ![w2irt](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/7ea924/32.png) [@w2irt](https://community.mp3tag.de/u/w2irt)
#### Post date: [July 17, 2012, 3:35pm UTC](https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651/3 "2012-07-17T15:35:29Z")

</div>

Wow. Worked perfectly! Thank you so much for saving me _ **hours** _ of tedious work--or, more likely, pushing this project off for another few years.

Thanks again!

> [@DetlevD](#):
>
> As always ... Mp3tag provides several ways to reach the goal ...  
> here is one way ... using the converter "Tag - Tag" ...
> 
> Step 1:
> 
>  
> 
> **Convert** | **Tag - Tag** | **ALT+5**
> 
>  
> 
> _Select format string_
> 
>  
> 
> Field: **TRACK**
> 
>  
> 
> Format string: **$regexp(%\_filename%,'^(.+?)\s0\*(\d+)\s.+?$','$2')**
> 
>  
> 
> Preview: **5**
> 
>  
> 
> Step 2:
> 
>  
> 
> **Convert** | **Tag - Tag** | **ALT+5**
> 
>  
> 
> _Select format string_
> 
>  
> 
> Field: **\_FILENAME**
> 
>  
> 
> Format string: **$regexp(%\_filename%,'^(.+?)\s0\*(\d+)\s.+?$','$1')**
> 
>  
> 
> Preview: **The Who - Won't Get Fooled Again**
> 
>  
> 
> DD.20120717.1905.CEST

---

<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:23pm UTC](https://community.mp3tag.de/t/track-numbers-from-malformed-filenames/13651/4 "2026-02-09T12:23:57Z")

</div>


