View Single Post
Old 07-07-2014, 05:49 PM   #520
eschwartz
Irrational Optimist
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
Posts: 6,483
Karma: 10683802
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch (Wifi only)
Quote:
Originally Posted by chaley View Post
TPM is Template Program Mode.

A template that produces what you want for the example you provided is
Code:
{author_sort:'re($, '([, ]+)(\w)\w*', '\1\2.')'}
I don't know it it will produce the right answer in all cases.
It truncates everything after the first word. Including the second author's first name (since it includes "& LN,[...]").

This should work, though:

Code:
program:

re(
	field('author_sort'),
	'(\w)\w+\b(?!,)',
	'\1.'
)

At some point I thought I'd try list_re to fix your example.

But I discovered this:

Code:
program:

list_re(
	field('author_sort'),
	'&',
	'(.*)',
	'\1'
)
gave me "LN1&FN1&LN2&FN2" -- isn't it supposed to search for "(.*)" and replace with "\1" on each list element where "&" is the separator? I cannot imagine what I might be doing wrong. But this looks completely crazy.

Last edited by eschwartz; 07-07-2014 at 05:56 PM.
eschwartz is online now   Reply With Quote