Peters Flexible RenAmiNg Kit (PFrank) Forum Index Peters Flexible RenAmiNg Kit (PFrank)
Support and Discussion Site for the PFrank File/Folder Renaming Tool (***NEW HOME PAGE*** "http://pfrank.atwebpages.com")
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert last '_' to a ' ' in 2008_01_20 Snow_005.jpg ?

 
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Regular Expressions
View previous topic :: View next topic  
Author Message
ssbn610g



Joined: 20 Feb 2009
Posts: 5
Location: North Carolina

PostPosted: Fri Feb 20, 2009 7:49 pm    Post subject: Convert last '_' to a ' ' in 2008_01_20 Snow_005.jpg ? Reply with quote

How would I convert the last '_' in the 'Prefix' in this string to a ' ' (space) 2008_01_20 Snow_005.jpg?

The first ten characters are dates. This means I cannot search and replace on '01' through '09' up to character 11.

As there are up to 999 possible numbers in the last counter I cannot search and replace on '00'

As the length of the file names varies I think I need to move backward from the end of the 'Prefix' 4 spaces, delete the '_' and insert a ' '.

Another stategy would to start a search and replace from the 11th character to the end of the file name.

I'm stuck on this one. Any help will be greatly appreciated.

Thanks, SSBN610G
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Sat Feb 21, 2009 5:22 am    Post subject: Reply with quote

Set the first search/replace row to the following (do not include the single quotes):


Search: '_([0-9]+)\.jpg'
Replace: ' \1.jpg'


On a match, the numbers after the underscore are placed into a group (group 1).
the replace row replaces the matched string with a blank and then follows that with group 1 + '.jpg' .

Hope this helps.

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ssbn610g



Joined: 20 Feb 2009
Posts: 5
Location: North Carolina

PostPosted: Sun Feb 22, 2009 8:38 pm    Post subject: That did it. But I don't understand _([0-9]+)\.jpg groups? Reply with quote

Your solution worked but I am still puzzed as to what the command is doing exactly. Would you please look at thsi below and let me know if my thinking is correct?

SEARCH SIDE
'_' What is the meaning of this?
I'm guessing '([1-9]+)' are possible group names (from 1 to nine) used if more than one '\' is encountered?
'\' Is what we are searching for?
'.jpg' Is appended to the replace to reestablish the file extension?

REPLACE SIDE
' \1.jpg' Puts the space where the '\' was? HOW?

It took seven commands to make this work:

SEARCH REPLACE
(?E)(.*).*
*Insert Folder before*Prefix*
*Delete All Characters in*Position*-1:-1*of*Prefix*
*Lower Case in*Extension*
*Insert Counter after*Prefix*
_([0-9]+)\.jpg \1.jpg

To get from: 2008_04_25 0394.JPG
To: 2008_04_25 104 Empire Circle Black Creek 0027.jpg
by using the folder name to replace the camera date and counter.

This is probably a mess but it is work for me now. If you could help me understand the commands I would be grateful and not have to both you with this again.

As there is no HELP on the command 'Insert text information after' could you give me guidance there as well? I tried to figure out the context but was unsuccessful.

THANKS SO MUCH, ssbn610g
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Mon Feb 23, 2009 3:55 am    Post subject: Reply with quote

1)
I'll try to explain how the regex works in your case.

The pattern is _([0-9]+)\.jpg

The sample filename is: '2008_01_20 Snow_005.jpg'.

You want to replace the last underscore with a blank.
And the last underscore is always followed by a number.

First of all the purpose of the search expression is to search the filename looking for a pattern match.
In this case the pattern starts with '_'
the next part of the pattern specified a numbers in the range 0-9. That is what the [0-9] means.
After the [0-9] is a plus sign. This means to look for one or more occurences of the previous character (which in this case is a range of characters)
So far we have: look for an underscore followed by at least 1 or more numbers.
Next we say that the numbers must be followed by: '.jpg'
This guarantees that when we have a match it will be the last underscore character followed by a number and not some other underscore/number sequence.
The last thing is the parentheses. These are used to define a group. Groups can be referenced later on in the replace expression. In this case we want to remember the numbers after the underscore so we surround the number expression in parenetheses. That is what the '([0-9]+)' does.
This group is the first (and only one) defined in the search pattern, therefore it is referred to as group 1.

The '\' before the '.' is required because the '.' character is a special character in regular expressions (just like the '[', ']', '+', '(', ')' characters).
If we want to match on a '[' in the name we would have to use '\['.
In this case we want to match on a dot (and not use it for the special function that the regular expression engine will use) so we have to use '\.'

that is it for the search pattern.

Now we want to replace everything matched from the '_' to the '.jpg' - this includes everything in between.

The replace expression is ' \1.jpg'

The first character in the replace pattern is a blank followed by the pattern found in group 1 (which in this case is the number 005) followed by the string '.jpg'
Groups 1 is specified by using '\1'.
If there was a second group defined it would be referred to as '\2'.

Hope that makes sense. If not there are tutorials on the PFrank web site as well as other links which will hopefully be more helpful.
See: http://www3.telus.net/pfrank/PFrankRegexLinks.html

2)
The 'insert text before/after' predefined commands are used to insert text found within the file to be renamed.
use the Options window to specify which text you would like to insert - e.g. the first word, or the fourth word, or the second line, etc.

You are right in that the help section for this feature was missed (it was one of the last insertion features added). I'll add the help section in a later release.


Peter.


Last edited by admin on Mon Feb 23, 2009 5:01 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ssbn610g



Joined: 20 Feb 2009
Posts: 5
Location: North Carolina

PostPosted: Mon Feb 23, 2009 2:53 pm    Post subject: Thanks for the detailed explanation - I was way off. Reply with quote

I really appreciate the time your took to educate me. My assumptions were based upon previous programming in C. My knowledge servered me badly in this case.

I will look more closey at the tutorials. This is really a great tool with massive time savings potential. I feel it will be much more productive with the kind help you have provided.

Respectfully yours, ssbn610g
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Regular Expressions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own Video Sharing Site

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com