complicated 0-filling: Is it too complicated for BRU ?

A swapping-ground for Regular Expression syntax

complicated 0-filling: Is it too complicated for BRU ?

Postby TNausE » Mon Dec 22, 2014 11:07 am

Hello,

i Need to Change MUCH filenames. Found your great tool, but i do wonder if it can do this:

Filename example: RA-1617_11006175messen.pdf

i Need to Change the first number behind "RA-"
i would like to add Zeros (Prefix) to fill the numer up to 6 Digits.
The number actually could be from 3-6 Digits.
If the file has already 6 Digits i don´t have to add Zeros.
The Part behind he number is not always there, even not the underscore _.
The fileextension is not always .pdf

Targetname-Example: RA-001617_11006175messen.pdf

Thank you in advance!
TNausE
 
Posts: 4
Joined: Mon Dec 22, 2014 10:54 am

Re: Is it too complicated für BRU?

Postby TheRegExpMaster » Mon Dec 22, 2014 12:03 pm

Hi, I'm not sure it's possible to do this (if someone knows how, please correct me).

But you can use 3 successive RegEx (for 3-digit numbers, 4 digits, and 5 digits) :

RegEx (1)

MATCH :
Code: Select all
^(RA-)(\d{3})(_?$|_.+)
REPLACE :
Code: Select all
\1000\2\3
"RA-617.pdf" will be renamed to "RA-000617.pdf".
"RA-617_.pdf" will be renamed to "RA-000617_.pdf".
"RA-617_11006175messen.pdf" will be renamed to "RA-000617_11006175messen.pdf".

MATCH :
Code: Select all
^(RA-)(\d{4})(_?$|_.+)
REPLACE :
Code: Select all
\100\2\3
"RA-6175.pdf" will be renamed to "RA-006175.pdf".
"RA-6175_.pdf" will be renamed to "RA-006175_.pdf".
"RA-6175_11006175messen.pdf" will be renamed to "RA-006175_11006175messen.pdf".

MATCH :
Code: Select all
^(RA-)(\d{5})(_?$|_.+)
REPLACE :
Code: Select all
\10\2\3
"RA-61753.pdf" will be renamed to "RA-061753.pdf".
"RA-61753_.pdf" will be renamed to "RA-061753_.pdf".
"RA-61753_11006175messen.pdf" will be renamed to "RA-061753_11006175messen.pdf".
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: complicated 0-filling: Is it too complicated for BRU ?

Postby TNausE » Mon Dec 22, 2014 2:34 pm

Thank you! it works like a charm.
I´ve been informed, that i will have to do the same in other cases with 2 to 8 Digits.
A RegExp solving all in once would be very nice.
But Thank you anyway for helping this far.
TNausE
 
Posts: 4
Joined: Mon Dec 22, 2014 10:54 am

Re: complicated 0-filling: Is it too complicated for BRU ?

Postby TNausE » Mon Dec 22, 2014 3:10 pm

One, hopefully last, question:

i need a nother reg.expr. for filling up with Zeros
The Special Thing is that there is sometime a "-" or sometimes a other character or even nothing in front of the number...

SE-123 should be SE000123
SE123 should be SE000123
SE.1234 helloworld should be SE001234 helloworld
SE.1234helloworld should be SE001234 helloworld
can you please help again?
the last case (missing blanc) is not important if making Problems....
TNausE
 
Posts: 4
Joined: Mon Dec 22, 2014 10:54 am

Re: complicated 0-filling: Is it too complicated for BRU ?

Postby TheRegExpMaster » Mon Dec 22, 2014 4:57 pm

TNausE wrote:I´ve been informed, that i will have to do the same in other cases with 2 to 8 Digits.
A RegExp solving all in once would be very nice.

To my knowledge, it's not possible to use 1 RegEx to solve all at once because RegEx just matches patterns, it doesn't count.
I think the only way to do what you want to do is to use a script to count the number of digits, then adjust the number of zeros to fill.


TNausE wrote:i need a nother reg.expr. for filling up with Zeros
The Special Thing is that there is sometime a "-" or sometimes a other character or even nothing in front of the number...


MATCH :
Code: Select all
^(SE)[^\d]?(\d{3})($|[^\d].*)
REPLACE :
Code: Select all
\1000\2\3
"SE-123.pdf" will be renamed "SE000123.pdf"
"SE123.pdf" will be renamed "SE000123.pdf"
"SE.123 helloworld.pdf" will be renamed "SE000123 helloworld.pdf"
"SE.123helloworld.pdf" will be renamed "SE001234helloworld.pdf"

MATCH :
Code: Select all
^(SE)[^\d]?(\d{4})($|[^\d].*)
REPLACE :
Code: Select all
\100\2\3
"SE-1234.pdf" will be renamed "SE001234.pdf"
"SE1234.pdf" will be renamed "SE001234.pdf"
"SE.1234 helloworld.pdf" will be renamed "SE001234 helloworld.pdf"
"SE.1234helloworld.pdf" will be renamed "SE001234helloworld.pdf"

MATCH :
Code: Select all
^(SE)[^\d]?(\d{5})($|[^\d].*)
REPLACE :
Code: Select all
\10\2\3
"SE-12345.pdf" will be renamed "SE012345.pdf"
"SE12345.pdf" will be renamed "SE012345.pdf"
"SE.12345 helloworld.pdf" will be renamed "SE012345 helloworld.pdf"
"SE.12345helloworld.pdf" will be renamed "SE012345helloworld.pdf"


Let me know if you need more help ;)
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: complicated 0-filling: Is it too complicated for BRU ?

Postby TNausE » Mon Dec 22, 2014 5:21 pm

thank you (again), but
"SE123.pdf" will be renamed "SE000123.pdf""
does not work.
"SE123" will be ignored...
"SE15 Golm.idw will be ignored..."
It seems that it depemds on the underscore
TNausE
 
Posts: 4
Joined: Mon Dec 22, 2014 10:54 am

Re: complicated 0-filling: Is it too complicated for BRU ?

Postby TheRegExpMaster » Mon Dec 22, 2014 5:28 pm

TNausE wrote:thank you (again), but
"SE123.pdf" will be renamed "SE000123.pdf""
does not work.
"SE123" will be ignored...

Make sure you entered the RegEx correctly. It works for me.

TNausE wrote:"SE15 Golm.idw will be ignored..."
It seems that it depemds on the underscore

I didn't cover the case when the filename had only 2 digits (I only gave for 3, 4 or 5 digits, assuming you would adapt it for lower digits).

For 2 digit filenames (like "SE15 Golm.idw"), use :

MATCH :
Code: Select all
^(SE)[^\d]?(\d{2})($|[^\d].*)
REPLACE :
Code: Select all
\10000\2\3


For 1 digit filenames (like "SE5 Golm.idw"), use :

MATCH :
Code: Select all
^(SE)[^\d]?(\d)($|[^\d].*)
REPLACE :
Code: Select all
\100000\2\3



Please, let me know if it works ...
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm


Return to Regular Expressions