dd_mmm_yyyy > yymmdd : regex and replace

A swapping-ground for Regular Expression syntax

dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Fri Mar 09, 2007 3:41 pm

Hi, I'm trying to change the name of a file which starts off life as:

wire_01_mar_2007

and I wish to transform this to:

070301_Res_FM_The_Wire_Presents.

ie. essentially transforming a dd_mmm_yyyy format to yymmdd

I've had partial success with my match string:

^(....)_(..)_(...)_20(..).*
and replace
\4\3\2_ResFM_The_Wire_Presents

but I still end up with the mmm month format in the output:
07mar01_Res_FM_The_Wire_Presents

I can even match a range of mmm month names in my match string thus:
^(....)_(..)_(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)_20(..).*

but alas, I'm struggling to find a way of converting the mmm format to a two digit mm format in my output.

Is there any way of performing any conditional replacement in BRU?
ie jan>>01, feb>>02 etc. I can't seem to find a way of doing this in the 'repl. (3)' section of BRU.

Note that I can't use the autodate function(s) since the creation date may bear no resemblance to the date embedded in the file name!
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Postby Admin » Fri Mar 09, 2007 4:18 pm

Hi,

Unfortunately there's not an option for this at the moment.

I've actually written a customised version of BRU which has a very advanced search and repalce facility in it, but it was done on a custom basis and I do not yet have permission to include this in the main build. It's a shame, as it would have exactly what you needed!



Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Postby spotburst » Fri Mar 09, 2007 4:26 pm

Thanks for such a quick response! - should I post this as a future revsion 'wish' or can I consider this something that may appear in a public release at a later date?
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Postby Admin » Fri Mar 09, 2007 5:02 pm

Hi,

Edit previous message: I have permission to include this logic in the public release, so it will be in the next release.


Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Postby KHL » Sun Mar 11, 2007 7:17 pm

Hi Jim,

that's good news, as I struggle with these RegExp strings any time I try...

Been married already?
Did you wear a kilt?
KHL
 
Posts: 128
Joined: Wed Mar 09, 2005 8:59 pm
Location: Germany

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Mon Oct 29, 2007 4:03 pm

Hi Jim - I remembered from back in March that in answer to my regex query (see below) you said "I have permission to include this logic in the public release, so it will be in the next release."

Is this now part of the new 2.7.0.1 release? If so, how do I do the conditional search/replace that I was originally after?

Cheers,
Spotburst


spotburst wrote:Hi, I'm trying to change the name of a file which starts off life as:

wire_01_mar_2007

and I wish to transform this to:

070301_Res_FM_The_Wire_Presents.

ie. essentially transforming a dd_mmm_yyyy format to yymmdd

I've had partial success with my match string:

^(....)_(..)_(...)_20(..).*
and replace
\4\3\2_ResFM_The_Wire_Presents

but I still end up with the mmm month format in the output:
07mar01_Res_FM_The_Wire_Presents

I can even match a range of mmm month names in my match string thus:
^(....)_(..)_(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)_20(..).*

but alas, I'm struggling to find a way of converting the mmm format to a two digit mm format in my output.

Is there any way of performing any conditional replacement in BRU?
ie jan>>01, feb>>02 etc. I can't seem to find a way of doing this in the 'repl. (3)' section of BRU.

Note that I can't use the autodate function(s) since the creation date may bear no resemblance to the date embedded in the file name!
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Postby Admin » Mon Oct 29, 2007 6:32 pm

Well, yes and no. It's logic that has been in there for a few releases, the "character translation" facility. This will allow you to convert Jan > 01, Feb > 02 etc. It's a bit indiscriminate, in that it operates across the entire string, but it should work ok.


Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby ckjian » Fri Nov 21, 2008 8:59 am

I know this is an old post. But I need a similar function to this. Has it been released already? If so, how can I use it?
ckjian
 
Posts: 5
Joined: Fri Nov 21, 2008 8:57 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Fri Nov 21, 2008 11:17 am

ckjian wrote:I know this is an old post. But I need a similar function to this. Has it been released already? If so, how can I use it?


Hi - I was the original poster of this conversion enquiry. The response at the time was to use the 'character translation' logic which can be found under the 'options' drop-down.
I couldn't get this to work in any way whatsoever. You're presented with a pop-up page where you (apparently) type in a 'from' string followed by an equals sign followed by a 'to' string. eg. Jan=01 (next line with CTRL+ENTER) Feb=02 (next line with CTRL+ENTER) Mar=03 etc. Unfortunately the Help section isn't very clear on actually making this work! I've tried allsorts eg. include quotes "Jan"="01" or even enter the 'from'/'to' strings as hex eg. 4A616E=3031 (though I can't quite see how this translation utility can decide what's hex and what's literal!). I'd still like to get this working so if Jim's still watching over this, perhaps he'll be able to tell me where I'm going wrong!
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Fri Nov 21, 2008 11:28 am

ckjian wrote:I know this is an old post. But I need a similar function to this. Has it been released already? If so, how can I use it?


BTW, The Help says:
If you wish to to convert several characters then you can separate the values by commas.
So the following example will convert ABC to DEF: 41,066,C=D,E,070

So in my Jan=01 example I tried:
J,a,n=0,1
also
4A,61,6E=30,31

...well I can see that translating 3 chars to 2 might be a problem, but I cannot even make this work for a single character yet.

I'm still puzzled (or stupid)
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby jimwillsher » Fri Nov 21, 2008 11:48 am

Hi,

This functionality is there, and works fine - I've just tested it myself and it works how it's described in the manual.

For example, I have a folder full of IMG_xxxx.jpg files (IMG_0001.jpg, IMG_0002.jpg etc.). In my Character Translations box I have entered this:

I,M=P,O,X,Y,Z


and my files now show up as

POXYZYG_0001.jpg
POXYZYG_0002.jpg

etc.


That's it, there's nothing else to it.

To answer a question from earlier in the thread, if the bit between the comma is one character it's treated as a letter; if it's two (e.g. 6F) it's treated as Hex; if it's three (e.g. 017) it's treated as decimal. That way you can perform replacements of non-keyboard characters.


Jim
jimwillsher
 
Posts: 63
Joined: Wed Sep 24, 2008 1:22 pm

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby ckjian » Fri Nov 21, 2008 12:08 pm

Dear Jim,
How can I rename the file names with the pattern of

KN21Nov2008.1.pdf

to

1KN211108.pdf

In brown is page no. of our files.
In Orange is date format.

Thank you very much to spotburst and Jim. I hope I can rename my files using this program or else I need to do a tedious job of renaming 1000+ of files.

Great program btw.
ckjian
 
Posts: 5
Joined: Fri Nov 21, 2008 8:57 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby jimwillsher » Fri Nov 21, 2008 12:20 pm

I'd probably do them in two phases. I'm assuming they don't all have Nov, some are Oct etc? In which case, use the Character Translations option:

J,a,n=0,1
F,e,b=0,2
...
N,o,v=1,1
D,e,c=1,2


etc.


Then handle the ".1" becoming "1." as a separate task. You can easily do the two in the same move of course, but no sense clouding the issues if it's a one-off task you have.


Jim
jimwillsher
 
Posts: 63
Joined: Wed Sep 24, 2008 1:22 pm

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Fri Nov 21, 2008 12:41 pm

Thanks Jim,

My life is now complete!
My problem was that I was using a olde version.
Like I said - I was being stupid....

BRU is simply amazing ... as usual.
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby spotburst » Fri Nov 21, 2008 3:46 pm

Hi ckjian,

In total your renaming will look like this:

In the main BRU window: Match (KN)(.*)(200)(.*)\.(.*)
Replace \5\1\20\4

If you highlight your file in the file lister old 'Name' to 'New name' will appear as:
KN21Nov2008.1.pdf 1KN21Nov08.pdf

you can see that the bracketed terms in the match string become fields-to-use in the replace string
ie.
1. (KN) is field 1, it matches the KN in your filename >> in the replace string \1 references the string KN
2. the first (.*) is field 2,it matches the 21Nov in your filename >> in the replace string \2 references the string 21Nov
3. (200) is field 3 or 200 >> you will not use this when you rebuild in the replace string (if you wanted to it would be \3)
4. the next (.*) is field 4, it matches 8 in your filename >> in the replace string \4 references the string 8
5. \. matches .
6. the next (.*) is filed 5, it matches your 'kind of siffixed' 1 >> in the replace string \5 references the string 1

so the replace string \5\1\20\4 catenates all of your wanted fields (and other literla bits-and-bobs) thus:
field 5 + field 1 + field 2 + 0 (literally) + field 4 = 1KN21Nov08.pdf

Now for the character translation (which I was originally having problems with):

Choose 'Options' drop-down in the main menu
Choose 'Character Translation' (or Ctrl+F6 if you like)
In the empty table that appears you need to enter:
J,a,n=0,1
F,e,b=0,2
M,a,r=0,3
A,p,r=0,4
etc.

This will the translate the 'Nov' in your 1KN21Nov08.pdf string to '11' yielding your desired result: 1KN211108.pdf

Hope this helps.
spotburst
 
Posts: 7
Joined: Fri Mar 09, 2007 11:22 am

Next

Return to Regular Expressions