View Single Post
Old 03-25-2023, 04:55 PM   #534
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Lys View Post
I feel there's an easy solution to this, but I can't find it on my own, so I need a bit of help.

I have a column (genre) that I use as a hierarchical tag.
Some examples of data I have in this column are:

Fiction.Classics.English Literature
Fiction.Classics.French Literature
Fiction.Historical Novel.Country: India
Fiction.Fantasy

Then I have another column (genre_list) that separates genres using:



And so far so good.


Now, I would like to have another column that excludes some items from genre_list.
The items I would like to remove are the ones matching the pattern: "xxxx Literature" and "Country: xxxx"

I know I can use list_difference to exclude values, but the list with the excluded values is compared term by term.
Is there a way to do so without having to list beforehand all occurrences of Country: xxxx, Xxxx Literature, but using the pattern?

I suspect that list_re() can do the job but it requires two steps. Example:
Code:
program:
	a = list_re($#genre, ',', '^(.* Literature|Country: .*)$', '');
	list_difference($#genre, a, ',')
The list_re() generates a list of items to remove, using a pattern I made up from your example. The list_difference() removes the matched items from #genre.
chaley is offline   Reply With Quote