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 

Explanation is missing in the 'Basic Renaming Guide'

 
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Comments
View previous topic :: View next topic  
Author Message
t-buch



Joined: 27 Aug 2007
Posts: 9
Location: Denmark

PostPosted: Thu Nov 20, 2008 11:38 am    Post subject: Explanation is missing in the 'Basic Renaming Guide' Reply with quote

You can read in the item 'Add Text' in the 'Basic Renaming Guide' http://www3.telus.net/pfrank/PFrankBasic.html

Row: 1
Search: '(?E)(.*?)'
Replace: '\1 match'


What is the last "?" for in "(.*?)"? I mean it works very well without adding the "?"
_________________
Thomas Buch
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Fri Nov 21, 2008 6:09 am    Post subject: Reply with quote

Thanks for pointing this out. The ? is unnecessary for this case.
I'll update the web page.

A ? when positioned after * or + is a non-greedy specifier.
Non-greedy means that the regex matcher will stop at the first fond match. Without the ? the matcher will be greedy and keep matching until the last possible match.

Try this out on main window of PFrank:

Row: 1
Search: '.*?a'
Replace: 'xxxa'

and place the word 'panama' into the sample previewer.
The result will be: 'xxxanama'

In this case the matcher was non-greedy and stopped after the first sequence ending in a.

If you remove the ?, the result will be: 'xxxa'
The reason is that the matcher kept searching for any character sequence ending in 'a' but it kept going until the last 'a'

Hope that helps.

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



Joined: 27 Aug 2007
Posts: 9
Location: Denmark

PostPosted: Fri Nov 21, 2008 6:29 am    Post subject: Reply with quote

Thanks for a good Explanation and thanks for the program

except that my result in your example 1 is "xxxaxxxaxxxa"

Also - what do you have to do if you just want to replace the first "a" with 2

so the result will be "p2nama" (original: panama)
_________________
Thomas Buch
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Fri Nov 21, 2008 7:12 am    Post subject: Reply with quote

Sorry - you're right again. I was playing with different examples and pasted the wrong one.
The expression pair I used was:

Row: 1
Search: '^.*?a'
Replace: 'xxxa'

To replace just the first 'a' with 2, try:

Row: 1
Search: '^(.*?)a'
Replace: '\g<1>2'


or you can use the PFrank extension (?n) to replace only the nth occurence:

Row: 1
Search: '(?1)a'
Replace: '2'
Back to top
View user's profile Send private message Send e-mail Visit poster's website
t-buch



Joined: 27 Aug 2007
Posts: 9
Location: Denmark

PostPosted: Sat Nov 22, 2008 11:51 am    Post subject: Reply with quote

Quote:
or you can use the PFrank extension (?n) to replace only the nth occurence:

Row: 1
Search: '(?1)a'
Replace: '2'


I try this (Sample: Elvis - Don't BE Cruel (Extra number).mp3):

Row: 1
Search: '(?2)E'
Replace: 'e'


The result was not what I expected:

Elvis - Don't Be cruel (Extra number).mp3)

but
elvis - Don't Be cruel (Extra number).mp3)
_________________
Thomas Buch
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Sat Nov 22, 2008 4:12 pm    Post subject: Reply with quote

I should read my own documentation.
The regex flag: '(?n)' where n is a number from 1-4, means to replace the first 'n' occurences of the matched expression.

There are examples of how to use it in the built-in help manual (search for "regex flag").

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Comments 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