View Single Post
Old 03-08-2021, 04:49 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,461
Karma: 8025600
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
This is what you are seeing.

It seems that what you want is:
Code:
for each book:
    if #genre contains text then add new_text to #kobocoll
As you are using action chains I would do this with a template in a single-field-edit action setting #kobocoll. The template would be something like this:
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
You can do it with two search/replace's. One would be something like this:
  • source "Template"
  • template
    Code:
    {#genre:'list_contains($, ',', '^Cozy Mystery$', 'Cozy Mysteries', '')'}
  • Search for: '(.*)'
  • Replace with '\1'
The other would be similar, with the other text values

Last edited by chaley; 03-08-2021 at 08:47 AM.
chaley is offline   Reply With Quote