View Single Post
Old 08-27-2017, 07:32 AM   #786
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,488
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by sweth View Post
Is there any way to apply a regex to each of the authors? list_re() doesn't quite fit the bill, as it eliminates entirely any authors that don't match the regex, and using it with a regex that could match authors with or without the annotation in []s requires using optional matching via ()? that throws off the replacement substitutions for one or the other case.
Try this:
Code:
{authors:'list_re($, ' & ', '^([^,]+), ([^[]+)(\[.*\]*|$)', '\2 \1 \3')'}
The change is to make the third group be able to match an empty string. Note that I changed the order of the group indicators in the replacement to produce what I think you are asking for.

Alternatively you can write a custom template function that does whatever you want.

EDIT: alternative 2: use list_re_group and separate out the two cases, as in the following:
Code:
{authors:'list_re_group($, ' & ', '.', '(^.*].*$)|(^.*$)', "[[$:'re($, '^([^,]+), ([^[]+) (\[.*\])', '\2 \1 \3')']]", "[[$:'re($, '^([^,]+), ([^[]+)', '\2 \1')']]")'}
The first group is anything that contains a ] or empty. The second group is either empty or anything that doesn't contain a ]. The two re functions in the group section handle the two cases. This second alternative handles names that are not LN, FN.

Last edited by chaley; 08-27-2017 at 07:51 AM.
chaley is offline   Reply With Quote