Quote:
Originally Posted by ownedbycats
On the inverse: How do I define a regex?
Since has_extra_files() is a bit slow, I'm adding the count to my admintags column with a template that:
1. Use a regex to match and remove any existing extra_files entries.
2. Generate a new extra_files entry.
3. Remove any entries matching 'extra_files:' exactly (zero files).
[...]
|
Line 6 assigns a string to the variable old_tags. It doesn't care what the string is. It seems that you are expecting list_difference() to use the regular expression contained in old_tags to create a list. It doesn't do that. The parameters are lists, not expressions to create lists.
This does what I think you want:
Code:
program:
#to be replaced with $#admintags
tags = 'extra_files:123, blahblah';
# Remove any extra_files: items from the list
removed_ef = list_re_group(tags, ',', '.', '^extra_files:\d*$', '');
# Add the correct extra_files item to the list
added_ef = list_join(',', removed_ef, ',', 'extra_files:' & has_extra_files(), ',')
NB: you can use select() to get the value of the extra_files item, as in:
Code:
select(added_ef, 'extra_files')
It will return '' if there isn't an extra_files: item or if the item ends with a colon (no extra files).
NB2: I wonder if it is worth adding a list_filter() template function, as in
Code:
list_filter(list, sep, regexp)
It would remove any item matching the regexp from the list. The list_re_group() above does that, but using it in this way isn't particularly obvious.
The same question arises for adding list_add()
Code:
list = list_add(list, ',', string)
It would add one item to an existing list. Clearly you can do this with list_join() (as done above), but something like list_add() would make it more clear that a single item is being appended to the list. It would also be faster.