View previous topic :: View next topic |
Author |
Message |
t-buch
Joined: 27 Aug 2007 Posts: 9 Location: Denmark
|
Posted: Mon Feb 06, 2012 1:45 pm Post subject: Replacing occurrence of Characters nr. X |
|
|
Sample text:
Baroque Masterpieces - A. Marcello - Oboe Concerto in D Minor - Adagio (02).wav
Replaced Text:
Baroque Masterpieces - A. Marcello - Oboe Concerto in D Minor, Adagio (02).wav
So here I want to replace the occurrence nr. 3 of the character " - " with ", ".
The two first occurrence of the character " - " I want to keep _________________ Thomas Buch |
|
Back to top |
|
 |
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Wed Feb 08, 2012 7:40 am Post subject: |
|
|
Try using the following in the custom renaming creator (do not include the single quotes).
Row: 1
Search: '^(.*?)(-)(.*?)(-)(.*?)(-)(.*)'
Replace: '\1\2\3\4\5, \7'
The filename search finds 7 groups and the new name replaces the 6th group (which is a dash), with a comma.
You can use subsequent rows to clean up the whitespace.
Hope that helps.
Peter. |
|
Back to top |
|
 |
t-buch
Joined: 27 Aug 2007 Posts: 9 Location: Denmark
|
Posted: Wed Feb 08, 2012 7:59 pm Post subject: |
|
|
Thanks, Peter
Is there a shorter regex if you could go from right to left?
I notice you are using "^" - what if you are using "$"??
----
By the way - I found my own solution before you send me your answer
This was a "two Rows solution":
Row: 1
Search: "(.*-)" Replace: "\1¤"
Row 2
Search: " -¤" Replace: "," _________________ Thomas Buch |
|
Back to top |
|
 |
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Wed Feb 08, 2012 9:22 pm Post subject: |
|
|
Yes you are correct in that you could use a much shorter expression that wouldn't depend on the number of dashes in the name. You just have to the non-greedy specifier (as you did with your solution).
something like:
search for '^(.*)-(.*)$' and replace with '\1, \2'
I think that will do the same as yours but in one row instead of 2.
Peter |
|
Back to top |
|
 |
|