Padding Random Number Prefix with 0's

A swapping-ground for Regular Expression syntax

Padding Random Number Prefix with 0's

Postby j.zulkeski » Thu Oct 15, 2015 8:18 pm

Searched, and found a few examples, but don't comprehend enough, so I'm asking for the solution.

I have many, many files with file names constructed like this:

random 7 or fewer digit number - filename.pdf

So, they all have <space> dashes in the same location.

Examples:

323 -this is file1.pdf
489834 - this is file two.pdf
9273 - this is file 3.pdf
2837261 -this is another file.pdf

I want to pad them all so that they end up:

0000323 -this is file1.pdf
0489834 - this is file two.pdf
0009273 - this is file3.pdf
2837261 -this is another file.pdf

Can someone tell me the regex to do this?
j.zulkeski
 
Posts: 4
Joined: Thu Oct 15, 2015 8:09 pm

Re: Padding a Random Number Prefix with missed 0's zeros

Postby Stefan » Fri Oct 16, 2015 7:25 am

FROM:
323 -this is file1.pdf
489834 - this is file two.pdf
9273 - this is file 3.pdf
2837261 -this is another file.pdf

TO:
0000323 -this is file1.pdf
0489834 - this is file two.pdf
0009273 - this is file3.pdf
2837261 -this is another file.pdf


Use this two steps:

-----------------------------------------------------------------

Round 1:
-------------

You have:
323 -this is file1.pdf
9273 - this is file 3.pdf
489834 - this is file two.pdf
2837261 -this is another file.pdf


Add(7)
Prefix: 000000
[Rename]

You got now, in between:
000000323 -this is file1.pdf
0000009273 - this is file 3.pdf
000000489834 - this is file two.pdf
0000002837261 -this is another file.pdf



-----------------------------------------------------------------

Round 2:
-------------

Un-set Add(7)

RegEx(1)
Match: 0*(\d{7}.+)
Repla: \1
[Rename]

Results to:
0000323 -this is file1.pdf
0009273 - this is file 3.pdf
0489834 - this is file two.pdf
2837261 -this is another file.pdf


-----------------------------------------------------------------

Done!

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

Re: Padding Random Number Prefix with 0's

Postby j.zulkeski » Tue Nov 10, 2015 3:04 pm

Wow, that worked awesome, and it would have taken me forever to figure out. Thank you so much!
j.zulkeski
 
Posts: 4
Joined: Thu Oct 15, 2015 8:09 pm

Re: Padding Random Number Prefix with 0's

Postby Stefan » Wed Nov 11, 2015 8:56 am

Great it worked.


Thx for feedback !



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


Return to Regular Expressions