Is there a way to separate out a list with an "if"?

Advanced Renamer forum
#1 : 28/11-24 08:08
Jenny
Posts: 5
I hope this makes sense. LOL

I have lists of books named like:

Stephen King - Salem's Lot.epub

When it's two authors, they should be Author One, Author Two - Book Title.epub

Some are Author One & Author Two - Book Title.epub

Okay, easy enough to change that. BUT... If the title has an ampersand in it, I can't just do a blanket replace, because the & should stay in a book title and I wouldn't want to replace it with a comma. So I have to set the replacement up but then just go in and look at what WOULD be changed and then manually change it.

So I suppose my question is... Is there a way to set it so to say if the & comes BEFORE the -, it changes it but not if it comes AFTER the - ?

Thanks all.
#2 : 28/11-24 08:49
Delta Foxtrot
Posts: 364
Reply to #1:

Hi Jenny,

This is not definitive, but for "Author One & Author Two - Book & Title.epub" this works:
REPLACE method:
Replace: "^([^&]+) & ([^-]+)- (.*)$" (no quotes)
With: "$1, $2- $3" (no quotes)
Reg. Exp.: Checked

Yields: "Author One, Author Two - Book & Title.epub"

I'm sure you can massage that expression to do what you need, right? :)

EDIT: If you right-click on the files list you can use "Mark/Mark none" and "Mark by pattern" to only select the files that fit that regular expression. Then you can see if it works on *your* files. END EDIT

Best,
DF


edited: 28/11-24 08:53
#3 : 28/11-24 09:06
Styb
Posts: 123
Reply to #1:
Hi all,
I am not sure if I understand it, but I think you can use the replace method by setting the ampersand replacement to comma only for the first occurrence.
#4 : 28/11-24 09:14
Delta Foxtrot
Posts: 364
Reply to #3:

Hey Styb,

Good call, buddy. Except that there's a space before the "&", so you'd do replace " &" (space + &) with a comma to format it correctly. The problem is that there might not be an & in the authors, which would then mess up a title with an &.

Best, my friend,
DF
#5 : 28/11-24 10:24
Jenny
Posts: 5
Reply to #2:

That's brilliant! Thank you! Worked great. :)
#6 : 28/11-24 13:15
Styb
Posts: 123
Reply to #4:
Hi DF,
I did not understand it. :)