Open Servinjesus1 opened 2 years ago
I agree pretty strongly with this. In my case, I want a naming scheme that behaves differently based on if the BBT citation key is pinned. You can easily check if the citation key is pinned by checking the extra
field, but i think it might be impossible because:
"If the match fails, this operation returns the input data"
Here's my current custom wildcard attempt that doesn't work as expected:
{"1": {"field": "extra", "operations": [{"function": "exec", "regex": "(Citation Key: )(\\w*|\\d*)", "group": 2}] } }
And here is an example naming rule that relies on the expected behavior:
{%1|%t}{ - %a}{ - %y}
In this specific case, an alternative solution would be a first-class "pinned citationkey" wildcard that's blank when unpinned, but I imagine that wouldn't be so nice because of the BBT dependency. I think a lightweight solution is to make failed matches count as empty fields.
Workaround is to use regex replacement, not exec. This more powerful tool does multiple matching, so you can define something like:
"1":
{
"field": "title",
"operations":
[
{
"function": "replace",
"regex": "(^.{10}).*(.{14}$)",
"replacement": "$1..$2"
}
]
}
as one of your custom replacement rules. In this case, it truncates anything longer than 24 characters to <first 10>..<last 14>
.
Currently, failing a regex check in a custom wildcard returns the input field unaltered. I think this is odd behavior since optional wildcards exist. These allow for users to do e.g.
{%1} | {%t}
if their custom wildcard%1
tries to regex the title field, and they really want the title field back undoctored if their regex fails, but only if the custom wildcard returns a "does not exist" condition rather than its current behavior. I'm not sure what DNE looks like in a Zotfile wildcard (an empty string?), but I could imagine it feasible to make regex evaluations return this if there's no match.