would like to retain name, but add 0 prior to random digits

A swapping-ground for Regular Expression syntax

would like to retain name, but add 0 prior to random digits

Postby heiserlon » Fri Dec 19, 2014 9:30 pm

I have a lot of very long file names containing strings with random single digits between two hyphens, such as in dates. I would like to make changes universally where this occurs to add a zero between the first hyphen and the digit. Currently, I can only return this result if the rest of the name deletes. Anything I add to the Match Expression gives me the rest of the name, but not the desired zero.
heiserlon
 
Posts: 3
Joined: Fri Dec 19, 2014 8:57 pm

Re: would like to retain name, but add 0 prior to random digits

Postby TheRegExpMaster » Sat Dec 20, 2014 2:26 am

please give an example of a file to rename, and the result you want.
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: would like to retain name, but add 0 prior to random digits

Postby TheRegExpMaster » Sat Dec 20, 2014 2:52 am

You can try this :

RegEx (1)
MATCH :
Code: Select all
(.*-)(\d)(-.*)

REPLACE :
Code: Select all
\10\2\3

But you will have to repeat it as many times as necessary if the filename has many single digits to replace.

"fdgfd-10-5-2014-gfd.txt" will be renamed to "fdgfd-10-05-2014-gfd.txt".
"fdgfd-1-5-2014-gfd.txt" will be renamed to "fdgfd-1-05-2014-gfd.txt" the 1st time then to "fdgfd-01-05-2014-gfd.txt" the 2nd time.
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: would like to retain name, but add 0 prior to random digits

Postby heiserlon » Sat Dec 20, 2014 9:36 pm

Thank you for your response. It will be Dec 29 before I am back to work and can give this a try. It seems logical to me, so hopefully it will work just fine. I'll get back with a definite answer once I return.
heiserlon
 
Posts: 3
Joined: Fri Dec 19, 2014 8:57 pm

Re: would like to retain name, but add 0 prior to random digits

Postby heiserlon » Mon Dec 29, 2014 3:45 pm

Thank you TheRegExpMaster ! I tried your solution and it works just fine. That's a relief, being totally new to BRU and to Regular Expressions. I greatly appreciate your help. :D
heiserlon
 
Posts: 3
Joined: Fri Dec 19, 2014 8:57 pm

Re: would like to retain name, but add 0 prior to random digits

Postby TheRegExpMaster » Mon Dec 29, 2014 5:33 pm

heiserlon wrote:Thank you TheRegExpMaster ! I tried your solution and it works just fine. That's a relief, being totally new to BRU and to Regular Expressions. I greatly appreciate your help. :D

You're welcome ;) If you need more help, just ask ;)
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm


Return to Regular Expressions