by Stefan » Thu May 30, 2013 3:33 pm
Interesting! First I thought it is not possible... but then I saw a way.
BEFORE:
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.cdg
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.mp3
SF175-01 - ANASTACIA Not That Kind .cdg
SF175-01 - ANASTACIA Not That Kind .mp3
AFTER:
SF175-01 - ANASTACIA - Not That Kind .cdg
SF175-01 - ANASTACIA - Not That Kind .mp3
SF175-03 - JENNIFER LOPEZ - My Love Don't Cost A Thing.cdg
SF175-03 - JENNIFER LOPEZ - My Love Don't Cost A Thing.mp3
RULE:
I want to add a " - " after each artist name but before the Title to separate artist from Title.
As you can see the name of the artists are all upper case and the title is usually first character upper case and second lower case.
USE:
RegEx(1)
Match: (.+?[A-Z]+) ([A-Z][a-z]+.+)
Replace: \1 - \2
Explanation:
Match non-greedy everything, followed by one-or-more upper case chars followed by a blank, store that in backreference group one.
Then match one upper case char followed by one-or-more lower case chars, followed by one-or-more of any signs, store in group two.
That regex will match
(.+?[A-Z]+) ([A-Z][a-z]+.+)
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.cdg
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.mp3
SF175-01 - ANASTACIA Not That Kind .cdg
SF175-01 - ANASTACIA Not That Kind .mp3
Note: that may work only with non-umlauts chars. Only with standard english chars.
In the replacement we add what was matched in group one, then literal blank-hyphen-blank by ourself, followed by what was matched in group two.
- - -
A more complex but also more weird example to extend this regex to cover more of different file names:
BEFORE:
SF175-01 - ANASTACIA Not That Kind .cdg
SF175-01 - ANASTACIA Not That Kind .mp3
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.cdg
SF175-03 - JENNIFER LOPEZ My Love Don't Cost A Thing.mp3
SF175-09 - U2 Stuck In a Moment With You.cdg
SF175-10 - A1 No More.cdg
SF175-11 - MARTINE McCUTCHEN On The Radio.mp3
SF999-98 - BOB DYLAN I Can't Get You Off Of My Mind.mp3
SF999-99 - BOB DYLAN A Fool Such As I.mp3
AFTER:
SF175-01 - ANASTACIA - Not That Kind .cdg
SF175-01 - ANASTACIA - Not That Kind .mp3
SF175-03 - JENNIFER LOPEZ - My Love Don't Cost A Thing.cdg
SF175-03 - JENNIFER LOPEZ - My Love Don't Cost A Thing.mp3
SF175-09 - U2 - Stuck In a Moment With You.cdg
SF175-10 - A1 - No More.cdg
SF175-11 - MARTINE - McCUTCHEN On The Radio.mp3
SF999-98 - BOB DYLAN - I Can't Get You Off Of My Mind.mp3
SF999-99 - BOB DYLAN - A Fool Such As I.mp3
USE:
RegEx(1)
Match: (.+?(?:[A-Z]\d|[A-Z]*)) ([A-Z] .+|[A-Z][a-z][A-Z]+.+|[A-Z][a-z]+.+)
Replace: \1 - \2
Explanation:
1. group
(.+?(?:[A-Z]\d|[A-Z]*))
consists of this parts
(.+? (?: [A-Z]\d | [A-Z]*) )
So we match non-greedy one-or-more of any sign, followed by one upper case char followed by one digit, OR,
one-or-more of upper case chars until an space,
to group one.
2. group
([A-Z] .+|[A-Z][a-z][A-Z]+.+|[A-Z][a-z]+.+)
consists of this parts
([A-Z] .+ | [A-Z][a-z][A-Z]+ .+ | [A-Z][a-z]+ .+)
Then we match one upper case char followed by one blank followed by one-or-more of any sign, OR,
one upper one lower one-or-more upper case chars followed by one-or-more of any sign, OR,
one upper case char followed by one-or-more lower case chars followed by one blank followed by one-or-more of any sign,
to group two.
Note: YMMV, depending on your file names...
But the not covered files may be a few only and can be modified by your self, right?
.