# Zero Padding Numbers

**URL:** https://community.mp3tag.de/t/zero-padding-numbers/13987
**Category:** Support
**Created:** [October 11, 2012, 6:17pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987 "2012-10-11T18:17:52Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 6:17pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/1 "2012-10-11T18:17:52Z")

</div>

Hi again, as I'm getting myself familiarized with mp3Tag, it's happen to me to come to new doubts:

Did you know if there is anyway to **ZERO PAD** numbers in tags or filename to a **fixed longitude**. If it's possible how to do that for just a specified number (considering tag or filename have more than one), and letting the others untouched, for example:

234234 This my file 3.12 (43).mp3  
234234 This my file A.12 (43).mp3

Zero padding to 3 only the number "12" at position **23** to get:

234234 This my file 3.012 (43).mp3  
234234 This my file A.012 (43).mp3

Thanks in advance...

N.B: I've discovered that $num(x,y) can make the work but not as specifically as I need

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [October 11, 2012, 6:28pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/2 "2012-10-11T18:28:12Z")

</div>

It could probably be done using a regular expression and submatches. You'd replace one of the submatches with something like $num($2,3). Need to know a lot more about how the existing strings are constructed, though, in order to create the regex. Maybe you could give some examples.

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 6:46pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/3 "2012-10-11T18:46:52Z")

</div>

Thanks for the reply,

It would be grateful if you can explain me how I can do that...

My files are the exact type as in the 1st post:

234234 English lesson 3.12 (43).mp3  
121211 English lesson A.12 (21).mp3

Zero padding to 3 only the number 12 in both files

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 7:03pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/4 "2012-10-11T19:03:24Z")

</div>

I've done a regular expression with the pattern:

%1.%2 %3 \>\>\> %1.$num(%2,3) %3

But that doesn't work, as I need it in an action

It is working in convert\>\>Filename-Filename, but I need it in action groups as mentioned.

---

<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: [October 11, 2012, 7:12pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/5 "2012-10-11T19:12:15Z")

</div>

> [@ykeyke](#):
>
> My files are the exact type as in the 1st post:  
> 234234 English lesson 3.12 (43).mp3  
> 121211 English lesson A.12 (21).mp3  
> Zero padding to 3 only the number 12 in both files

 

**Convert** | **Filename - Filename** | **ALT+3**

 

_Select format string_

 

Old filename pattern:  
**%1 %2 %3.%4 %5**

 

New filename pattern:  
**%1 %2 %3.$num(%4,3) %5**

 

Preview  
From:  
**234234 English lesson 3.12 (43).mp3**  
To:  
**234234 English lesson 3.012 (43).mp3**

 

It would be more convenient not to work on the filename directly, but to work with a tag-field which contains the proper value resp. use $num(x,y) when assembling the filename.  
Please show us the format string, which assembles the filename.

From what tag-field does the number 12 come from?  
If it is the track number, then use ... **$num(%TRACK%,3)**... and all is fine.

DD.20121011.2317.CEST

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 7:17pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/6 "2012-10-11T19:17:24Z")

</div>

> [@DetlevD](#):
>
> **Convert** | **Filename - Filename** | **ALT+3**
> 
>  
> 
> _Select format string_
> 
>  
> 
> Old filename pattern:  
> **%1 %2 %3.%4 %5**
> 
>  
> 
> New filename pattern:  
> **%1 %2 %3.$num(%4,3) %5**
> 
>  
> 
> Preview  
> From:  
> **234234 English lesson 3.12 (43).mp3**  
> To:  
> **234234 English lesson 3.012 (43).mp3**
> 
>  
> 
> It would be more convenient not to work on the filename directly, but to work with a tag-field which contains the proper value resp. use $num(x,y) when assembling the filename.
> 
> DD.20121011.2310.CEST

Is it the only way to do it, can't do it in actions??

In actions it doesn't work in filename, nor in tags ![:w00t:](https://community.mp3tag.de/uploads/default/original/1X/cb01eca72fe9339ff6f3ec9f1e3c5fe002be0f0a.gif ":w00t:") ![:w00t:](https://community.mp3tag.de/uploads/default/original/1X/cb01eca72fe9339ff6f3ec9f1e3c5fe002be0f0a.gif ":w00t:") ![:w00t:](https://community.mp3tag.de/uploads/default/original/1X/cb01eca72fe9339ff6f3ec9f1e3c5fe002be0f0a.gif ":w00t:")

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 7:26pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/7 "2012-10-11T19:26:58Z")

</div>

> [@DetlevD](#):
>
> From what tag-field does the number 12 come from?  
> If it is the track number, then use ... **$num(%TRACK%,3)**... and all is fine.

The 12 is part of the filename and title, it is the number of lesson, the track would be the first number in the filename of 6 digits

---

<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: [October 11, 2012, 7:39pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/8 "2012-10-11T19:39:11Z")

</div>

> [@ykeyke](#):
>
> The 12 is part of the filename and title, it is the number of lesson, the track would be the first number in the filename of 6 digits

Well ... anywhere at the beginning of your workflow you can split the given title string (e. g. "English lesson 3.12 (43)" into components e. g. "header chapter step" or so ...  
... then assemble the parts as you need it to create the new filename ...

**%TRACK%%OtherNumbers%' '%HEADER%' '%CHAPTER%'.'$num(%STEP%,3)' ('%OtherStuff%')'**

DD.20121011.2337.CEST

Or try something like this ... designed around the corner ...

**$regexp($regexp(%\_filename%,'^(\d+)\s(.+?)\s(\d+)\.(\d+)\s(.+)$','$1 $2 $3.000$4 $5'),'^(\d+)\s(.+?)\s(\d+)\.0\*(\d\d\d+)\s(.+)$','$1 $2 $3.$4 $5')**

DD.20121011.2349.CEST

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 8:28pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/9 "2012-10-11T20:28:09Z")

</div>

> [@DetlevD](#):
>
> Well ... anywhere at the beginning of your workflow you can split the given title string (e. g. "English lesson 3.12 (43)" into components e. g. "header chapter step" or so ...  
> ... then assemble the parts as you need it to create the new filename ...
> 
> **%TRACK%%OtherNumbers%' '%HEADER%' '%CHAPTER'.'$num(%STEP%,3)' ('%OtherStuff%')'**
> 
> DD.20121011.2337.CEST
> 
> Or try something like this ... designed around the corner ...
> 
> **$regexp($regexp(%\_filename%,'^(\d+)\s(.+?)\s(\d+)\.(\d+)\s(.+)$','$1 $2 $3.000$4 $5'),'^(\d+)\s(.+?)\s(\d+)\.0\*(\d\d\d+)\s(.+)$','$1 $2 $3.$4 $5')**
> 
> DD.20121011.2349.CEST

Thanks DetlevD, I'm trying to make any of the two suggestions works, by now none does ☹ . I'll continue fighting... I'll let you know...

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 11, 2012, 10:08pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/10 "2012-10-11T22:08:50Z")

</div>

Uff, at last I get it, thanks a lot; Based on your: $regexp($regexp(%\_filename%,'^(\d+)\s(.+?)\s(\d+).(\d+)\s(.+)$','$1 $2 $3.000$4 $5'),'^(\d+)\s(.+?)\s(\d+).0\*(\d\d\d+)\s(.+)$','$1 $2 $3.$4 $5'), DetlevD, I find a way to do it, here it comes for use of anyone who may need it:

Regular expression: (.+?).(\d+)\s(.+)$  
Replace with: $1.$num($2,3) $3

Just a last doubt: What is the difference between **(.+?)** and **(.+)**? What's function had the **?** here? In mp3Tag it says: _? repeated zero or one times only_, but I can't see the functionality???

Greetings

---

<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: [October 12, 2012, 4:04am UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/11 "2012-10-12T04:04:04Z")

</div>

> [@ykeyke](#):
>
> ... What is the difference between **(.+?)** and **(.+)**? What's function had the **?** here? ...

See there ...  
[http://www.regular-expressions.info/repeat.html](http://www.regular-expressions.info/repeat.html)  
... there is a good explanation about "greediness" and "lazyness" of regular expressions.

When writing a regular expression for Mp3tag, e. g. when splitting a text string into parts, basically I prefer lazy quantifiers wherever possible.  
So it can happen, that there is a question mark used as a limiter for greediness, where the limitation may not strictly required.

Try out if this works ...

**^(.+?)\.(\d+)\s(.+)$**

Try out if that works ...

**^(.+)\.(\d+)\s(.+)$**

... then use the regular expression, which gives the best result.

DD.20121012.0802.CEST

---

<div class="post-metadata">

### Author: ![ykeyke](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/y/d26b3c/32.png) [@ykeyke](https://community.mp3tag.de/u/ykeyke)
#### Post date: [October 12, 2012, 5:54pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/12 "2012-10-12T17:54:56Z")

</div>

> [@DetlevD](#):
>
> Try out if this works ...
> 
> **^(.+?)\.(\d+)\s(.+)$**
> 
> Try out if that works ...
> 
> **^(.+)\.(\d+)\s(.+)$**

It seems that in my case the ? makes no difference, I get the same results.

Thanks a lot.

---

<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:24pm UTC](https://community.mp3tag.de/t/zero-padding-numbers/13987/13 "2026-02-09T12:24:06Z")

</div>


