Zero Padding Numbers

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

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.

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

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.

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

234234 English lesson 3.12 (43).mp3
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.


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: :w00t: :w00t:

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%')'


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')


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

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???


See there ...
... 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 ...


Try out if that works ...


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


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

Thanks a lot.