![]() |
#1 |
Member
![]() Posts: 13
Karma: 10
Join Date: Oct 2019
Device: paperwhite; android
|
Selecting first names from strings like A B/Q R
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. |
![]() |
![]() |
![]() |
#2 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: list_re(field('#text'), '/', '^(.*)\b.*$', '\1') Code:
{#text:'list_re($, '/', '^(.*)\b.*$', '\1')'} 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. |
|
![]() |
![]() |
![]() |
#3 |
Member
![]() Posts: 13
Karma: 10
Join Date: Oct 2019
Device: paperwhite; android
|
thanks for the quick reply! unfortunately both of these are giving me the full names still...
|
![]() |
![]() |
![]() |
#4 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The correct templates are Code:
program: list_re(field('#text'), '/', '^(..*?)\b.*$', '\1') Code:
{#text:'list_re($, '/', '^(..*?)\b.*$', '\1')'} |
|
![]() |
![]() |
![]() |
#5 |
Member
![]() Posts: 13
Karma: 10
Join Date: Oct 2019
Device: paperwhite; android
|
perfect, thank you so much!
|
![]() |
![]() |
![]() |
#6 |
Member
![]() Posts: 13
Karma: 10
Join Date: Oct 2019
Device: paperwhite; android
|
After testing a few files with this, I have some more questions...
1) Is it possible to return the shortened form for both when there's more than one pair of names in the field separated by a comma? 2) Can it account for " & " in place of "/", i.e., "John Doe & Jim Smith" to "John & Jim"? (This isn't as big a deal, but I do have some fields like that.) |
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Moderator Notice
Moved from the sticky recipes thread |
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,445
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: list_re(re(field('#text'), ',', '/'), '/', '^(..*?)\b.*$', '\1') Code:
program: list_re(field('authors'), ' & ', '^(..*?)\b.*$', '\1') |
|
![]() |
![]() |
![]() |
#9 |
Member
![]() Posts: 13
Karma: 10
Join Date: Oct 2019
Device: paperwhite; android
|
Thanks again! I ended up making a second custom column for the pairs separated by & so my covers can show both shortened forms when both are present. (This probably sounds overcomplicated, but in fanfiction tagging, / and & are semantically different, and sometimes a story includes both with different pairs of names, so...)
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pen names and real names | whiteowl | Library Management | 4 | 01-19-2020 06:22 PM |
automatic changing christian names and family names | sjefclaassen | Calibre | 3 | 09-29-2017 06:59 AM |
Braces in strings | Jellby | Development | 4 | 09-08-2014 01:10 PM |
How to exclude strings before and after | ElMiko | Sigil | 14 | 07-21-2012 06:34 PM |
What are these strings for? | Jellby | Calibre | 2 | 05-22-2011 01:08 PM |