View Single Post
Old 06-25-2014, 02:43 AM   #4
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,336
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
This is an interesting case. In effect, it wants a function that allows a template to be applied to each group matched in the search regular expression, in effect providing similar functionality as python's match groups. This function, having a variable number of arguments, would look something like:
Code:
re_groups(field, search_expr, template_for_group_1, t_for_g_2, ...)
The group would be named '$' when the template for that group is called. The result is the field with each match of 'search_expr' replaced by the result of evaluating the template for each group and concatenating the groups.

For the situation being discussed in this thread and using eschwartz's example, one would use something like
Code:
re_groups(field('author_sort'), '([^,]+), (.+)', 'program: uppercase($)', 'program: $')
or
Code:
re_groups(field('author_sort'), '([^,]+), (.+)', "[[$:uppercase()]]", '[[$]]')
I will look at whether such a function is buildable.

Last edited by chaley; 06-25-2014 at 03:19 AM. Reason: changed syntax
chaley is offline   Reply With Quote