View Single Post
Old 06-03-2023, 05:55 PM   #629
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,462
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I have a list of tags such as Fiction.Cultures & Regions.Canada and Nonfiction.Cultures & Regions.Asia.China.

I'd like to remove any tag including "Cultures & Regions" from the list before splitting it.

I tried a regex list_difference but it didn't seem to work:

Code:
program:
	list_difference($tags, '(.*)Cultures & Regions(.*)', ',');)
(Additionally, I also want to do the same with something like a list_intersection to extract the culture & region items.)
Most of the list functions don't take a regular expression to specify the list. They require an actual list.

You can do what you want with list_re_group(). This template uses that function to return a list of items not containing "Cultures & Regions" by setting that list item to the empty string.
Code:
program:
	l = list_re_group($tags, ',', '.', '(^.*Cultures & Regions.*$)', '')
You can use list_re()'s include_re to do the opposite -- extract all items containing "Cultures & Regions".
chaley is offline   Reply With Quote