Padding Numbers with Zeros

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

Padding Numbers with Zeros

Postby DeepBlueSea » Thu Sep 13, 2007 10:34 pm

True enough shhac, however, what you don't know (and how would you) is that I'm trying to learn the code (which can be a little intimidating) used in the Bulk Rename Utility that will allow me to do even more than what is given here. Your idea would have gotten the job done but I wouldn't have learnt much. That's why I didn't just want the right code, but I also needed to know why it worked the way it did. Thanks for your interest.
Posts: 8
Joined: Sat Jul 14, 2007 11:54 pm
Location: USA

Re: Padding Numbers with Zeros

Postby BrianM » Wed Oct 23, 2013 2:25 pm

Hi all,
Sorry if this is reactivating an old post, but it's exactly what I'm trying to do, but I'm struggling to get it to work for me in my circumstances.

I am trying to normalise a several thousand set of document names, and wish to pad the numbering within the filename to match an associated database.

The filenames are like this:


and I want to get them like this

I can find the number after the hyphen and get RegEx to add one or two leading zeros, but cannot seem to get it to work on 1 digit ONLY numbers, only on 2 digit ONLY numbers.


adds a leading zero on two digit filenames, so prEN2155-20EdP1.pdf becomes prEN2155-020EdP1.pdf
and it ignores prEN2155-4EdP1.pdf


adds two leading zeros to all the numbers, including any already changed.

Can anybody help a noob?


Posts: 1
Joined: Wed Oct 23, 2013 1:15 pm

Re: Padding Numbers with Zeros

Postby Stefan » Wed Oct 23, 2013 3:39 pm

Hi and welcome Brian.

First, you don't have to escape the hyphen.

Second, RegEx is a pattern matching system, you have to tell him exactly what you want to match.

In your second example, "(.+)\-(\d)(.+)", you match one digit, followed by one-or-more of ANY sign, this includes punctuation, chars and digits.
Also you first example "(.+)\-(\d\d)(.+)" would match two-or-more digits, as \d\d will match two digits and .+ will match another digits, or signs or chars.

The RegEx help distributed with BRU do not describe every available expression possibility. Read a good RegEx tutorial
or at least the last post in the thread > Board index ‹ Bulk Rename Utility ‹ Regular Expressions > Getting help with Regular Expressions

One solution for you would be to match one digit, followed by a not-a-digit sign by using "\D" like (.+)-(\d)(\D.+)

Match: (.+-)(\d)(\D.+)
Repla: \100\2\3


Match: (.+-)(\d\D.+)
Repla: \100\2

Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Suggestions