View Single Post
Old 08-27-2017, 05:01 AM   #785
sweth
Connoisseur
sweth began at the beginning.
 
Posts: 68
Karma: 10
Join Date: May 2015
Device: Kindle Fire 7 (7G), Kindle PW (2G), Kindle Scribe
Is there any way to have a plugboard apply a regular expression transformation to each author individually? I use LN, FN format for authors in calibre, which gets switched to FN LN when I load books onto my Kindle--but I also use suffixes in brackets to indicate people in the authors field who aren't actually authors. So for example for Neil Gaiman's Graveyard Book, the authors field has

Gaiman, Neil & McKean, Dave [illustrator]

which then shows up on the Kindle as

Neil Gaiman & Dave [illustrator] McKean

. I had thought that a plugboard entry like

Code:
{authors:'re($, "^([^,]+), ([^[]+) (\[.*\])","\1 \3, \2")'}
would apply that re() to each of the authors, so that the authors would show up on the Kindle as

Neil Gaiman & Dave McKean [illustrator]

but instead it is applying it to the entire contents of that field, so that the author on the Kindle shows up as

Neil Gaiman [illustrator] & Dave McKean

. If I knew I would only ever have two entries in the authors field and that only the second one was annotated, I could tweak the regex accordingly, but I often have anthologies where the first entry in authors is "Some Guy [editor]" and then later on in a long list of authors might be "Other Guy [foreword]", as well as other variants that make a single regex for the entire authors field impractical.

Is there any way to apply a regex to each of the authors? list_re() doesn't quite fit the bill, as it eliminates entirely any authors that don't match the regex, and using it with a regex that could match authors with or without the annotation in []s requires using optional matching via ()? that throws off the replacement substitutions for one or the other case.
sweth is offline   Reply With Quote