Moving and swapping date formats with regex

A swapping-ground for Regular Expression syntax

Moving and swapping date formats with regex

Postby regexnewbie » Wed Jan 16, 2013 1:27 am

Hi there!

I'm trying to move the date from the end of a filename to the beginning, and change the format at the same time. Currently the filename format is like so:

"BRU HAS SOME FANCY FEATURES 15 01 2012.doc"

and I'd like it to read:

"2012 01 15 BRU HAS SOME FANCY FEATURES.doc"

So, I've tried this regular expression:

^([A-Z *]) ([0-9][0-9]) ([0-9][0-9]) ([0-9][0-9][0-9][0-9])
\4 \3 \2 \1

But it doesn't seem to do anything. Do I need to specify groups for each word in the filename (could be a problem when filenames have a varying number of words)? Or is there a way to delineate a longer string including spaces? I've only done a little regex matching before, and moving/renaming is completely new to me. :oops:
regexnewbie
 
Posts: 1
Joined: Wed Jan 16, 2013 1:15 am

Re: Moving and swapping date formats with regex

Postby Stefan » Sat Jan 19, 2013 1:24 am

FROM:
"BRU HAS SOME FANCY FEATURES 15 01 2012.doc"

TO:
"2012 01 15 BRU HAS SOME FANCY FEATURES.doc"

TRY untested:
(.+) (\d\d) (\d\d) (\d\d\d\d)
\4 \3 \2 \1
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions