Replace a series of dashes, but leave the last dash

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Replace a series of dashes, but leave the last dash

Postby Fatbat » Tue Aug 02, 2016 7:45 am

Hello.

I've got a bunch of music files that have had dashes inserted between each artist's name who was involved in the song. They look like this...

Artist - Title
Artist - Artist - Title
Artist - Artist - Artist - Title
Artist - Artist - Artist - Artist - Title

etc.

Ideally I would like them to look like this, replacing the space dash space with comma space, leaving the last space dash space...

Artist - Title
Artist, Artist - Title
Artist, Artist, Artist - Title
Artist, Artist, Artist, Artist - Title

Any ideas? Thanks for your time!
Fatbat
 
Posts: 9
Joined: Wed Apr 09, 2008 3:54 pm

Re: Replace a series of dashes, but leave the last dash

Postby Admin » Wed Aug 03, 2016 1:08 am

This can be done easily with Javascript in one pass, but javascript requires a BRU commercial license. If you have one, I can post the script. thanks
Admin
Site Admin
 
Posts: 1504
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replace a series of dashes, but leave the last dash

Postby Fatbat » Wed Aug 03, 2016 5:09 am

So just to be clear about what we are talking about, I need to buy your commercial license? That's fine, I've used your program for some years, so I'm not adverse to doing so. I'll sort this out and get back to you.
Fatbat
 
Posts: 9
Joined: Wed Apr 09, 2008 3:54 pm

Re: Replace a series of dashes, but leave the last dash

Postby Admin » Wed Aug 03, 2016 6:40 am

Try this Javascript function in BRU 3.0 (or newer)

Code: Select all
function replaceAll(str, find, replace) {
  return str.replace(new RegExp(find, 'g'), replace);
}

var str = name, replacement = '<';
str = str.replace(/-([^-]*)$/,replacement+'$1'); //replace last - into <

str = replaceAll(str, ' -', ','); //replace all remaining  - into ,
str = replaceAll(str, '-', ',');  //replace all remaining - into ,

str = str.replace(/<([^<]*)$/,'-'+'$1'); //replace last < into -

newName = str;
Admin
Site Admin
 
Posts: 1504
Joined: Tue Mar 08, 2005 8:39 pm


Return to Javascript Renaming


cron