|
|
#1 |
|
Lurker
![]() Posts: 1
Karma: 10
Join Date: Jun 2024
Device: none
|
Using RegEx to find and replace in varying columns
Hi all, forgive me if the answer to this is obvious; everything I've learned about coding has been from this forum and from Stack Overflow answers, but this time I can't seem to find an answer.
I use Calibre primarily for fanfics, and as anyone familiar with ao3 knows, there's a lot of variation in the spelling/punctuation/grammar of tags for tags of the same meaning. So, after I've imported the fics to Calibre with the FanFicFare plugin, I use template functions in Action Chains to edit those tags to make them universal, and then move specific ones into my own custom columns (separating freeform tags, characters, ships, etc). (Since many authors have a tendency to put things like ships and characters in with their freeform tags, I find it easier to do the bulk of the editing in Calibre functions with regular expressions rather than in the edits you can do in FanFicFare's ini file at import, and then distribute them to their columns after the fact.) My question comes with using those Calibre stored template functions. Say I want to remove the last names of characters—I have five different columns that I can make those edits to, and therefore five functions saved, all identical except for the very first line where I call the specific column. How can I make it to where I can change what column to act on when I call the function from Action Chains? So, an example of the saved function saved as "clipNames_characters": Code:
python:
def evaluate(book, context):
t0 = context.funcs.field('#characters');
t1 = context.funcs.re(t0,"Search Terms 1", "Replacement 1");
t2 = context.funcs.re(t1,"Search Terms 2", "Replacement 2");
***(etc multiple lines of the rest of the code)***
return t193
Code:
program:clipNames_characters(); I hope this all made sense; let me know if you have questions or answers.
|
|
|
|
![]() |
| Tags |
| custom col, regex, stored templates, template functions |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New to regex find and replace! | ksimpson1986 | Sigil | 2 | 11-06-2016 11:29 AM |
| regex cannot find to replace | eschwartz | Editor | 11 | 02-03-2014 11:00 PM |
| Regex find and replace | SanatyrZeo | Sigil | 5 | 10-29-2012 07:03 AM |
| RegEx find and replace | iblesq | Sigil | 1 | 01-10-2011 09:26 PM |
| REGEX find and replace help please | potestus | Sigil | 13 | 09-18-2010 04:14 PM |