#1 2011-06-02 07:06

pstein
Member
Registered: 2006-10-28
Posts: 43

Need help with two regular expressions

I have two scenarios where I need some regular expressions to rename a bulk of files:

1.) I have files of  the format:

......<blank>03.2011<blank>.....<extension>
or
......(03.2010).....<extension>

"03.2011" could be another month+year as well e.g. 07.2010.
How do I setup a regular expression to rename them to

......<blank>2011.03<blank>.....<extension>
resp.
......(2011.03).....<extension>

2.) Starting with filenames with the pattern:

......<blank>2011.03.<extension>
or
......<blank>(2011.03).<extension>

I would like to move the location of the date part to the beginning:

2011.03<blank>..........<extension>

Mind that the old blank has moved as well.

How would a regular expression look like for this?

Thank you
Peter

Offline

#2 2011-06-02 10:52

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

Re: Need help with two regular expressions

Hi Peter,
RegEx is an pattern-matching system.
So we have to know how we can match that pattern we want... are this the only digits in the whole string?

For 1.) you want to exchange the month with the year?

FROM:
......<blank>03.2011<blank>.....<extension>
......(03.2010).....<extension>
TO:
......<blank>2011.03<blank>.....<extension>
......(2011.03).....<extension>


For 2.) you want to move dates, from just before the extension, to the begin of the string?
While moving the blank from left to right.

FROM:
......<blank>2011.03.<extension>
......<blank>(2011.03).<extension>
TO:
2011.03<blank>..........<extension>
(2011.03)<blank>..........<extension>


PS: it's always good to provide real (and all possible) file names to have an better impact how it looks.
Our solution can only be as good as your examples are (and mostly work for the provided examples only instead of all possibles possibilities)


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 2011-06-04 13:01

pstein
Member
Registered: 2006-10-28
Posts: 43

Re: Need help with two regular expressions

Ok more precisely:

1.) *<blank or "(">mm.yyyy<blank or ")">*.<extension>

where mm are two digits representing month number and yyyy are 4 digits representing year number
should be converted to

*<blank or "(">yyyy.mm<blank or ")">*.<extension>

Sample:                          scenario23 (12.2010) extend.log
converted by regexp to:   scenario23 (2010.12) extend.log

2.) *<blank><nothing or "(">yyyy.mm<nothing or ")">.<extension>

should be converted to

yyyy.mm<blank>*.<extension>

Sample:                        scenario55 (2009.07).log
converted by regexp to: 2009.07 scenario55.log

Offline

#4 2011-06-04 16:35

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

Re: Need help with two regular expressions

Still not clear.
Is "2.)" an second step after "1)"?
Or are that two different scenarios?
Should only dates from the end be moved to the begin?
Where are your "real live" examples?



I simple search now for two digits (months) following by an dot and 4 digits (year).
Then i exchange this two groups form <month>.<year> to <year>.<month>.
Then i move dates (only that one from the end) to the beginning.
Then i remove remaining blanks and empty parentheses.
That works for the "examples" you have provided:


FROM:
scenario23 (11.2010) extend.log
scenario24 12.2010 extend.log
scenario55 (05.2008).log
scenario56 07.2009.log
TO:
scenario23 2010.11 extend.log
scenario24 2010.12 extend.log
05.2008 scenario55.log
07.2009 scenario56.log
USE:
Exchange month with year:
1) RegEx: Replace expression "^(.+?)\(*(\d{2})\.(\d{4})\)*(.*)" with "$1$3.$2$4" (skip extension)
Move date from the end to the begin:
2) RegEx: Replace expression "^(.+)(\d{4})\.(\d{2})\)*$" with "$3.$2 $1" (skip extension)
Clean up:
3) CleanUp: Strip out contents of brackets (..) , Fix spaces (skip extension)



- - -

To move all dates, no matter if from end or from in-between too, to the front use this:

FROM:
scenario23 (11.2010) extend.log
scenario24 12.2010 extend.log
scenario55 (05.2008).log
scenario56 07.2009.log
TO:
2010.11 scenario23 extend.log
2010.12 scenario24 extend.log
2008.05 scenario55.log
2009.07 scenario56.log

Rules:
Exchanges month with year and move dates to the begin:
1) RegEx: Replace expression "^(.+)(\d{2})\.(\d{4})(.*)$" with "$3.$2 $1$4" (skip extension)
Clean up:
2) CleanUp: Strip out contents of brackets (..) , Fix spaces (skip extension)


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