#1 2010-08-22 18:19

steppinwolf
Member
Registered: 2010-08-22
Posts: 4

Another Date Formatting RegEx

Hello, I'm using the following regex, but in Renamer preview or analyser nothing changes:

Expression: ^(Jan|Feb|Mar|Apr|May|Jun|Jul|Apr|Sep|Oct|Nov|Dec)\s{1}(\d{2})\s{1}(\d{4})$
Replace:       $3-$1-$2

Example of Expected Behavior:
Before:  Coast to Coast - Apr 01 2010 - Hour 2.mp3
After:    Coast to Coast - 2010-Apr-01 - Hour 2.mp3

Actually I plan to write another rule to change MMM to mm, but would like to get this working first.

Update: regexlib.com's tester confirms the expression is working as expected--detecting the date and putting the correct piece in each variable. I've used this replace metacharacter string successfully with other expressions...

Last edited by steppinwolf (2010-08-22 18:51)

Offline

#2 2010-08-22 20:53

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Another Date Formatting RegEx

Hi wolf, welcome.

steppinwolf wrote:

Hello, I'm using the following regex, but in Renamer preview or analyser nothing changes:

Expression: ^(Jan|Feb|Mar|Apr|May|Jun|Jul|Apr|Sep|Oct|Nov|Dec)\s{1}(\d{2})\s{1}(\d{4})$
Replace:       $3-$1-$2

Example of Expected Behavior:
Before:  Coast to Coast - Apr 01 2010 - Hour 2.mp3
After:    Coast to Coast - 2010-Apr-01 - Hour 2.mp3

Actually I plan to write another rule to change MMM to mm, but would like to get this working first.

Update: regexlib.com's tester confirms the expression is working as expected--detecting the date and putting the correct piece in each variable. I've used this replace metacharacter string successfully with other expressions...

You have to know that the RegEx meta sign
"^" means "Start of string" (or start of file name here) and
"$" means "End of String".

So your expression would work on an file name like "Apr 01 2010"

For an file name like "Coast to Coast - Apr 01 2010 - Hour 2.mp3" you should use
Expression: ^(.+)(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1}(\d{2})\s{1}(\d{4})(.+)$
Replace:       $1$4-$2-$3$5

but with ReNamer you could also match an part of an string (instead of the whole string between "^" and "$") so you may just use
Expression: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1}(\d{2})\s{1}(\d{4})
Replace:       $3-$1-$2

All with "[X] Skip extension" enabled.


- - -

Additional note (in case you or an other don't know):
"{1}" means: one amount of the regex just before.
But an regex expression itself match every time only ONE occurrences already, so using the regex without the {1} would work too.
Expression: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2})\s(\d{4})
Replace:       $3-$1-$2

or even this will work:
Expression: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{2}) (\d{4})
Replace:       $3-$1-$2

or, if you like to know, your example file names looks like you could use:
Expression: " (\w{3}) (\d{2}) (\d{4}) "
Replace:       $3-$1-$2
too.


- - -

Regarding the "MMM to mm,"

you could use an Replace Rule:
Find: Jan*|*Feb*|*Mar*|*Apr*|*May*|*Jun*|*Jul*|*Aug*|*Sep*|*Oct*|*Nov*|*Dec
Repl: 01*|*02*|*03*|*04*|*05*|*06*|*07*|*08*|*09*|*10*|*11*|*12



HTH? big_smile

Last edited by Stefan (2010-08-22 21:06)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2010-08-23 05:27

steppinwolf
Member
Registered: 2010-08-22
Posts: 4

Re: Another Date Formatting RegEx

Thanks Stefan, your post is like getting a regex class for free! Actually I just made a small donation through PayPal in appreciation for ReNamer and your expert assistance.

I just started playing around with regular expressions yesterday, so there's a lot I didn't know. Will give these a try.

Offline

#4 2010-08-24 02:26

steppinwolf
Member
Registered: 2010-08-22
Posts: 4

Re: Another Date Formatting RegEx

The regex variations I tried worked perfectly as did the replace rule. No surprise to you I'm sure. Saved me a lot of time with 354 files to rename. Thanks again.

Offline

#5 2010-08-24 06:28

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Another Date Formatting RegEx

Many thanks for the feedback, great ReNamer could help you.

Thanks for the donation also in behalf of Denis.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB