# Zero Padding Numbers, Episode 2

**URL:** https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998
**Category:** Support
**Created:** [October 15, 2012, 12:07am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998 "2012-10-15T00:07:54Z")
**Posts on this page:** 11
**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 15, 2012, 12:07am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/1 "2012-10-15T00:07:54Z")

</div>

Hi again,

For another type of files mp3, I'm trying to zero pad them, but this time there's no '.' which I had taken as a reference in the first topic about this subject.

The files are like:

**123456 English Class 67.mp3  
654321 English Listening 23.mp3**

I need to zero pad to 3 the number after Class, and to 2 the number after Listening, so I create an action group, which contains:

1-Format Value: A:  
$if($neql($strstr(%\_Filename%,lass),0),3,0)  
(N.B: Here I put lass, because if I put class, it seems that there is sensibility to cases, and don't work, any suggestion welcomed)

2-Format Value: A:  
$if($neql($strstr(%\_Filename%,istening),0),2,0)  
(N.B: Here I put istening, because if I put listening, it seems that there is sensibility to cases, and don't work, any suggestion welcomed)

3-Format Value: Filename  
$if($eql(%A%,3),$regexp(%\_Filename%,'^(\d+)\s([A-Za-z]+)\s([A-Za-z]+)\s([A-Za-z]+)\s(\d+)\s(-\d+)$','$1 $2 $3 $4 000$5 (-$6)'),%\_Filename%)

4-Format Value: Filename  
$if($eql(%A%,3),$regexp(%\_Filename%,'^(\d+)\s([A-Za-z]+)\s([A-Za-z]+)\s([A-Za-z]+)\s(\d+)\s(-\d+)$','$1 $2 $3 $4 00$5 (-$6)'),%\_Filename%)

BUT SURPRISE, AS YOU CAN IMAGINE, IT DIDN'T WORK, the 1 and 2 actions are OK, but I don't know what I'm doing wrong with the 3 and 4. I would like if you can correct me the error, but I'm opened to other ideas.

Any one can help? Thanks

---

<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 15, 2012, 12:39am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/2 "2012-10-15T00:39:13Z")

</div>

For the case sensitivity problem, you can turn %\_filename% to all upper or lower case for the comparison.

$strstr($lower(%\_filename%),'class')

In regular expressions you can use ^ and $ as "anchors" to mean the start and end of the string, respectively. In your case you know the digits are always at the end, so using $ is the key and would function very much like the period in the last regular expression. The important part of what you want to match is a sequence consisting of a series of digits that follow a space, and are followed by the end of the string.

See: [http://www.regular-expressions.info/anchors.html](http://www.regular-expressions.info/anchors.html)

Something like the following (I didn't test this):

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

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [October 15, 2012, 1:55am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/3 "2012-10-15T01:55:41Z")

</div>

> [@ykeyke](#):
>
> The files are like:
> 
> **123456 English Class 67.mp3  
> 654321 English Listening 23.mp3**
> 
> I need to zero pad to 3 the number after Class, and to 2 the number after Listening, so I create an action group, which contains:

You can turn on case insentive with: (?i)  
You can turn off case insentive with: (?-i)

You can place these at different intervals of your reg exp or just have one at the start of your reg exp such as '(?i)' to not worry what case the text string is.

**Padding zeros \_FILENAME:**  **EDIT: Read the OPs Problem wrong.**

_Action type:_ **Format value**  
_Field:_ **\_FILENAME**  
_Formatstring:_ **$regexp** ( **$regexp** ( **$regexp** ( **%\_filename%** ,**'^(\d{6}.+)\s+([0-9]+)$'**, **'$1 000$2'** ),**'(?i)^(\d{6}.+\s+listening\s+)\d+(\d{2})$'**, **'$1$2'** ),**'(?i)^(\d{6}.+\s+class\s+)\d+(\d{3})$'**, **'$1$2'** )

 

**Results:**

_123456 English Class 7_

_654321 English Listening 23  
123456 English Class 00000000000006  
123456 English class 07  
654321 English listening 23  
123456 English class 00000000000006_

 

> > >

 

_123456 English Class 007  
654321 English Listening 23  
123456 English Class 006  
123456 English class 007  
654321 English listening 23  
123456 English class 006_

 

If you want to change the padding at any stage just change the **(\d{2})** or **(\d{3})** where you see fit.

---

<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 15, 2012, 3:45am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/4 "2012-10-15T03:45:08Z")

</div>

If you use regexp() there's an optional fourth parameter: 1 for case-insensitive, 0 for case-sensitive (default).

Another way to approach this would be to use _Replace with regular expression_ actions. With this type of action there's a checkbox for case-sensitivity.

1. 

_Action type:_ **Replace with regular expression**  
_Field:_ **\_FILENAME**  
_Regular expression:_ **^(\d{6}\s+.+\s+Class)\s+(\d+).**  
_Replace matches with:_ **$1 $num($2,3).**  
[] _case-sensitive comparison_

1. 

_Action type:_ **Replace with regular expression**  
_Field:_ **\_FILENAME**  
_Regular expression:_ **^(\d{6}\s+.+\s+Listening)\s+(\d+).**  
_Replace matches with:_ **$1 $num($2,2).**  
[] _case-sensitive comparison_

\_FILENAME in this context includes the file extension, so you can use the period following the digits instead of $ to anchor the expression. The file extension itself will remain unchanged.

---

<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 15, 2012, 5:22am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/5 "2012-10-15T05:22:01Z")

</div>

> [@ykeyke](#):
>
> ...The files are like:  
> **123456 English Class 67.mp3  
> 654321 English Listening 23.mp3**  
> I need to zero pad to 3 the number after Class, and to 2 the number after Listening ...

Case 1  
Action: Format value  
Field : \_FILENAME  
Format string: **$regexp($regexp(%\_filename%,'^(\d+.+\sclass\s)(\d+)$','\1000\2',1),'^(.+?)0\*(\d{3})$','\1\2')**  
Preview  
From:  
123456 English Class 7  
123456 English Class 67  
123456 English Class 167  
To:  
123456 English Class 007  
123456 English Class 067  
123456 English Class 167

Case 2  
Action: Format value  
Field : \_FILENAME  
Format string: **$regexp($regexp(%\_filename%,'^(\d+.+\slistening\s)(\d+)$','\1000\2',1),'^(.+?)0\*(\d{2})$','\1\2')**  
Preview  
From:  
654321 English Listening 3.mp3  
654321 English Listening 23.mp3  
To:  
654321 English Listening 03.mp3  
654321 English Listening 23.mp3

DD.20121014.0919.CEST

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [October 15, 2012, 11:15am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/6 "2012-10-15T11:15:17Z")

</div>

Read the OPs post wrong. Changed [post #3](https://community.mp3tag.de/t/13998/3).

---

<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 15, 2012, 11:32pm UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/7 "2012-10-15T23:32:21Z")

</div>

**stevehero** , **DetlevD** and **JJ Johnson** , thanks a lot to all of you, all your suggestions were different but functional, pretty than mine. I appreciate the trick to avoid to worry about cases. I erroneously imagined that with one $regexp, I can do the work, but it seems to need more than one, I'll try to study all suggestions, to better understand the construction of the regular expressions (examples like yours are the best way to clarify ideas). Always there is something new to learn.

Thank you again, and in case of doubts, I'll let you know...

Greetings

---

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [October 16, 2012, 9:28am UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/8 "2012-10-16T09:28:29Z")

</div>

> [@ykeyke](#):
>
> **...** I erroneously imagined that with one $regexp, I can do the work, but it seems to need more than one, I'll try to study all suggestions, to better understand the construction of the regular expressions (examples like yours are the best way to clarify ideas). Always there is something new to learn.

1 _$regexp_ in mine pads 3 leading zero's (maximum number you require) and the other 2 fix them to have only 2 or 3 depending on your requirements, so as you can see that is 3 steps and the minimum amount of $regexp you can have.

I'll try break down the _$regexp_ best I can:

**$regexp($regexp($regexp(%\_filename%,'^(\d{6}.+)\s+([0-9]+),'$1 000$2'),'(?i)^(\d{6}.+\s+listening\s+)\d+(\d{2}),'$1$2'),'(?i)^(\d{6}.+\s+class\s+)\d+(\d{3}),'$1$2')**  **$regexp** :

1st: **$regexp(%\_filename%,'^(\d{6}.+)\s+([0-9]+),'$1 000$2')**  
2nd: **$regexp(****,'(?i)^(\d{6}.+\s+listening\s+)\d+(\d{2}),'$1$2')**  
3rd: **$regexp(****,'(?i)^(\d{6}.+\s+class\s+)\d+(\d{3}),'$1$2')**

**Explanation: PART 01**

**$regexp(%\_filename%,** replaces the pattern specified by the regular expression expr

```
			in the string <!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto--><b><!--coloro:#0000FF--><span style="color:#0000FF"><!--/coloro-->%_filename%<!--colorc--></span><!--/colorc--></b><!--fontc--></span><!--/fontc--> by repl. The fourth optional parameter enables ignore case (1) or disables the ignore case setting (0). Please note that you have to escape comma and other special characters in expr.<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto--><b> </b><!--fontc--></span><!--/fontc--><!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto--><b><!--coloro:#0000FF--><span style="color:#0000FF"><!--/coloro-->' <!--colorc--></span><!--/colorc--></b><!--fontc--></span><!--/fontc-->Wraps the regexp (needed in certain regexp to stop errors but I use it in all)<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto--><b><!--coloro:#0000FF--><span style="color:#0000FF"><!--/coloro-->

```

^ Anchors to the start of string  
**(\d{6}.+)** Start capture #1 **(** with exactly 6 digits **\d{6}** then any character any amount of times between 1/infinity **.+** then end capture #1 **)**

**\s+** White-space any amount of times **+** between 1/infinity 

**([0-9]+)** Start capture #2 **(** with any digit from 0-9 **[0-9]** (same as '\d') any amount of times **+** between 1/infinity **+** then end capture #2 **)**

 **$** Anchors to the end of string **'** Wraps the regexp **,** Separates the regexp with the replace 

**'** Wraps the regexp

 **$1 000$2** Replaces with capture #1 whitespace 000#2 (This is where the 0's are padded) 

**'** Wraps the regexp

 **)** Closes **$regexp(** 

**Before:**  
_123456 English Class 67_  
_654321 English Listening 3_  
**After:**  
_123456 English Class 00067_  
_654321 English Listening 0003_

 

**Explanation: PART 02**

 **$regexp(** Start $regexp #2 **,** Use %\_filename% from before 

**'** Wraps the regexp

 **(?i)** Match reminder of regexp with the options: case insensitive 

**^** Anchors to the start of string

 **(\d{6}****.+\s+listening\s+) **Start capture #1** ( **with exactly 6 digits** (\d{6} **then any character any amount of times between 1/infinity**.+ **white-space** \s **any amount of times** + **between 1/infinity and end capture #2** )**

**\d+** Any Digit **\d** any amount of times **+** between 1/infinity **(\d{2})** Start capture #2 ( with exactly 6 digits (\d{6} then any character any amount of times between 1/infinity .+ white-space \s any amount of times + between 1/infinity

 **$** Anchors to the end of string **\*\*** Important the this is here as you need to anchor the regexp to the end for **(\d{2})** to work properly **'** Wraps the regexp **,** Separates the regexp with the replace **'** Wraps the regexp 

**$1$2** Replaces with capture #1 then #2 \*\*Notice that **\d+** was outside a capture like **(\d{2})** therefore not replacing it and leaving the result with 2 paddings.

 **'** Wraps the regexp **)** Closes **$regexp(**  **Before:** 

_654321 English Listening 0003_  
**After:**  
_654321 English Listening 03_

 

**Explanation: PART 03**  
Much the same as PART 02 only **class** is changed and **(\d{3})** because you want different rules to pad **class** with 3 numbers.

  **Before:** 

_654321 English Class 0003_  
**After:**  
_654321 English Class 003_

---

<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 16, 2012, 2:01pm UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/9 "2012-10-16T14:01:12Z")

</div>

This _could_ be done with a single _Replace with regular expression_ action, but I've always favored using multiple simple actions. One reason being that they can be more easily understood when you go back to them months later. But also because by being more atomic, they can be easily rearranged, edited, removed, etc.

_Action type:_ **Replace with regular expression**  
_Field:_ **\_FILENAME**  
_Regular expression:_ **^(\d{6}\s+.+)\s+(Class|Listening)\s+(\d+).**  
_Replace matches with:_ **$1 $2 $num($3,$if($eql($lower($2),class),3,2)).**  
[] _case-sensitive comparison_

---

<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 18, 2012, 3:06pm UTC](https://community.mp3tag.de/t/zero-padding-numbers-episode-2/13998/10 "2012-10-18T15:06:16Z")

</div>

WOOOW, That's what I call a magisterial explanation, thank you stevehero, you clarify me a lot of concepts.  
Yours JJ Johnson is also nice, what I intended to do in four actions, you was able to put in one.

Sincerely, Thanks to all of you...

Your disciple ![:book:](https://community.mp3tag.de/uploads/default/original/1X/0036d5b68f6226c53f6c68abfd0a7b8096fd4505.gif ":book:")

---

<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-episode-2/13998/11 "2026-02-09T12:24:07Z")

</div>


