Reg Expression conversion of date?

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Reg Expression conversion of date?

Postby dave458 » Tue Sep 29, 2009 3:38 am

Hi,

I have many files that include the date in the filename, which is accurate, while the date stored in meta-data is not.

I do not need to change the meta-data (which I see from other discussions is not possible), but i would like to reformat the date. Usually this means converting filename-23Feb09.pdf to 20090223-filename.pdf

Can this be done using some fancy Regular Expression.

Cheers,

Dave
dave458
 
Posts: 1
Joined: Tue Sep 29, 2009 3:31 am

Re: Reg Expression conversion of date?

Postby Admin » Wed Sep 30, 2009 2:05 pm

Is the date format always fixed, i.e.
filename-23Feb09
filename-06Jan03

etc, that is always the last 7 chars after a -

thanks
Admin
Site Admin
 
Posts: 2351
Joined: Tue Mar 08, 2005 8:39 pm

Re: Reg Expression conversion of date?

Postby tklein » Wed Nov 25, 2009 9:58 pm

I have a similar question.

And no, the filename before the date is not always the same number of characters.

I need the following:
filenameone 01-01-08
filenametwo 01-02-08
filenamethree 01-03-08

to be:
filenameone 080101
filenametwo 080102
filenamethree 080103

Thanks for the help!
tklein
 
Posts: 1
Joined: Wed Nov 25, 2009 9:52 pm

Re: Reg Expression conversion of date?

Postby Stefan » Thu Nov 26, 2009 9:32 am

Hi T, welcome.

tklein wrote:I need the following:
filenameone 01-01-08
filenametwo 01-02-08
filenamethree 01-03-08

to be:
filenameone 080101
filenametwo 080102
filenamethree 080103


Solution:
-- search for one-or-more of any char or sign ==> .+
------- group this for back reference ==> () ==> (.+) ==> filenamethree
-- then search for an blank
-- then for two digits and group them ==> (\d\d) ===> 01
-- then for an dash ==> -
-- then for two digits and group them ==> (\d\d) ===> 03
-- then for an dash ==> -
-- then for two digits and group them ==> (\d\d) ===> 08

On filenamethree 01-03-08 => "filenamethree" is hold in group "\1", "01" in group "2", "03" in "3" and "08" in "4"
Then simple do an new order in the replacement, first group \1, then group \4\2\3, or whatever you like.


RegEx(1)
Match: (.+) (\d\d)-(\d\d)-(\d\d)
Repl: \1 \4\2\3

HTH?
If yes, please help two others too.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to BRU Support