View Single Post
Old 10-03-2023, 05:59 AM   #958
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,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by sardonica View Post
I'm sure this is the easiest solution ever but the Calibre Template Language guide is going entirely over my head. I'd like to understand how to modify the code below to include the first 2 (rather than 1) characters of each word in text string. But, if the text string is just one word, I'd like to include the first 4 characters. I thought the "\1" indicated the number of characters but was definitely wrong on that front

{#textstring:re([\s]?([^\s])[^\s]+(\s|$),\1)}

Example:
Lord of the Rings --> LoofthRi
Villains --> Vill

Thank you in advance!
Code:
{series:'contains($, ' ', re($,'\s*(\S{{,2}})\S*(?:\s|$)','\1'), re($, '^(\S{{,4}}).*$', '\1'))'}
chaley is offline   Reply With Quote