|
|
#1 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,371
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Help with a search&replace
I wanted to make some search & replaces for an Action Chain to populate one column based on values from another, like these (note the latter should also be 'prepend to field,' I forgot to set it before screenshotting it):
As the results show, it also copies all values from Genre (tag-like composite) instead of just the one i want. What should I do?
Last edited by ownedbycats; 03-07-2021 at 11:07 PM. |
|
|
|
|
|
#2 |
|
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,034
Karma: 30277960
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
|
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,526
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Search and replace operates on the individual values, not the set of them, changing only the text that matches. Any values that are not matched are not changed. Said another way, S&R does:
Code:
for each item in the list:
find text in item that matches the search expression
replace that text with the replacement expression
return the list with replacements
It seems that what you want is: Code:
for each book:
if #genre contains text then add new_text to #kobocoll
Code:
program:
g = field('#genre');
k = field('#kobocoll');
if list_contains(g, ',', '^Cozy Mystery$', '1', '') then
k = list_union(k, 'Cozy Mysteries', ',')
fi;
if list_contains(g, ',', '^(Fantasy|Science Fiction)$', '1', '') then
k = list_union(k, 'Fantasy & Sci-Fi', ',')
fi;
k
Last edited by chaley; 03-08-2021 at 09:47 AM. |
|
|
|
|
|
#4 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,371
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I'll try that. Hopefully it won't overwrite other existing entries.
![]() EDIT: I used the template. It worked and did not remove existing entries. Last edited by ownedbycats; 03-08-2021 at 08:05 PM. |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search & Replace changes in 3.0 | Phssthpok | Editor | 4 | 06-21-2017 05:04 AM |
| Regex in search problems (NOT Search&Replace; the search bar) | lairdb | Calibre | 3 | 03-15-2017 08:10 PM |
| Search & Replace Help | paulfiera | Conversion | 7 | 08-06-2015 04:52 AM |
| Help with a search & replace | mmholt | Library Management | 11 | 10-21-2011 07:49 PM |
| Search & Replace | Pat Nickholds | Sigil | 2 | 10-22-2010 12:18 AM |