Quote:
Originally Posted by sweth
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.