View Single Post
Old 10-16-2011, 03:21 AM   #6
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Jade Aislin View Post
That is almost exactly what I want. However, I want it to be more general. When I tried it, I found that I had to put in the subitem path. Using your 'comics' as an example, if I had a subitem book.comics and I wanted to get the last item for any genre that contained comics I had to write out book.comics. My problem is that I also want to be able to get the last subitems of newspaper.comics. I want to be able to get the last item from each genre no matter what the higher up subitems are (book or newspaper).
To repeat, you want to match some genre names no matter where they appear in the hierarchy, beginning, middle, or end. For those that match, print the last item in the hierarchy, which might be the matched item. The following does that for comics and history.
Code:
{#genre:'subitems(list_re($, ',', '(\.|^)(comics|history)\.', ''), -1, 0)'||}
The change was to not anchor (in the regular expression sense) the match to the first item, which is what I thought you wanted. Instead, the new regexp matches 'comics' or 'history' between dots (an internal item), between the beginning and a dot (the first item), between a dot and the end (the last item), or between the beginning and the end (the only item).

The reason to add the || at the end is to keep the template parser from being confused by the | characters in the regular expression.
chaley is offline   Reply With Quote