View previous topic :: View next topic |
Author |
Message |
t-buch
Joined: 27 Aug 2007 Posts: 9 Location: Denmark
|
Posted: Thu Nov 20, 2008 11:38 am Post subject: Explanation is missing in the 'Basic Renaming Guide' |
|
|
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 |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Fri Nov 21, 2008 6:09 am Post subject: |
|
|
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 |
|
|
t-buch
Joined: 27 Aug 2007 Posts: 9 Location: Denmark
|
Posted: Fri Nov 21, 2008 6:29 am Post subject: |
|
|
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 |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Fri Nov 21, 2008 7:12 am Post subject: |
|
|
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 |
|
|
t-buch
Joined: 27 Aug 2007 Posts: 9 Location: Denmark
|
Posted: Sat Nov 22, 2008 11:51 am Post subject: |
|
|
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 |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Sat Nov 22, 2008 4:12 pm Post subject: |
|
|
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 |
|
|
|