View Single Post
Old 07-26-2020, 05:33 AM   #2
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by vargr View Post
Hello, can anyone help with a template I'm trying to make for cover generation? I want it to take a text field that's a series of 2+ names separated by slashes, and return just the first word of each name, retaining the slashes.

i.e., so that "John Doe/Jim Smith" would show as "John/Jim" on the generated cover.
One of these should do it. Using general program mode:
Code:
program: list_re(field('#text'), '/', '^(.*)\b.*$', '\1')
Using template program mode:
Code:
{#text:'list_re($, '/', '^(.*)\b.*$', '\1')'}
Change #text to be the lookup name of your text column.

The above also handles single names. For example "John Doe/Fred/Jim Smith" produces "/John/Fred/Jim". If you don't want that then change the \b to a space character.

Last edited by chaley; 07-26-2020 at 12:09 PM.
chaley is offline   Reply With Quote