Zotfile: customize journal abbreviation to rename files
I would like to customize journal abbreviation using the first letter of each word of the journal name.
I defined a new wildcard in extensions.zotfile.wildcards.user:
"z": {"field": "publicationTitle", "operations":[{"function":"exec","regex": "\\b[a-zA-Z]"}]}
And defined the renaming rules as:
{%z-}{%t}
However, it got me the first letter of the journal name, rather than the first letter of each word.
e.g., for “Journal of Risk and Uncertainty-Valuing mortality risk in China”,
I expect:
JoRaU-Valuing mortality risk in China
Yet I got:
J-Valuing mortality risk in China,
I would like to know how can I fix it.
Thank you very much.
Zotero version: 5.0.89
OS: Windows 10 OS Version 1909 (Build 18363.778)
I defined a new wildcard in extensions.zotfile.wildcards.user:
"z": {"field": "publicationTitle", "operations":[{"function":"exec","regex": "\\b[a-zA-Z]"}]}
And defined the renaming rules as:
{%z-}{%t}
However, it got me the first letter of the journal name, rather than the first letter of each word.
e.g., for “Journal of Risk and Uncertainty-Valuing mortality risk in China”,
I expect:
JoRaU-Valuing mortality risk in China
Yet I got:
J-Valuing mortality risk in China,
I would like to know how can I fix it.
Thank you very much.
Zotero version: 5.0.89
OS: Windows 10 OS Version 1909 (Build 18363.778)
{
"1": {
"field": "publicationTitle",
"operations": [{
"function": "replace",
"regex": "\\B[a-zA-Z]",
"replacement": ""
},
{
"function": "replace",
"regex": " ",
"replacement": ""
}
]
}
}
You could also add
{"function": "toLowerCase"}
or{"function": "toUpperCase"}
to the list of operations.Zotfile's documentation has links to Mozilla's explanation of the
exec()
andreplace()
functions. There, you can read: "The exec() method [...] [r]eturns a result array, or null." See also here: https://stackoverflow.com/a/5283091.You can test your regular expressions at https://regex101.com/. Minify or beautify your JSON at https://jsoncompare.com/.
I've been trying to edit the wildcard but without success.
I'm searching for the regular expression to abbreviate the journal using the first letter of each word, excluding transition words (such as "of", "and", etc).
EX: "Journal of Volcanology and Geothermal Research" ---> return "JVGR"
Currently, the solution provided by @qqbb returns "JoVaGR".
I've tried testing the expression at https://regex101.com/ but failed miserably, as one cannot simply copy/paste the JSON field "regex" into the regular expression box and expect it to work.
Thanks very much for any suggestion!
For some reason using \\B[A-Z] appears to fail, as it returns the full journal string, without spaces:
"Journal of Volcanology and Geothermal Research" ---> "JournalofVolcanologyandGeothermalResearch"
In addition to your suggestion, I've added an operation to the JSON which removes everything in a journal title after a special character such as ":".
EX:
"Journal of Geophysical Research: Atmospheres" --> JGR
"Journal of Volcanology and Geothermal Research" --> JVGR
Here is the wildcard:
{
"z": {
"field": "publicationTitle",
"operations": [{
"function": "replace",
"regex": "\\s*[.:;?!|].*",
"replacement": ""
},
{
"function": "replace",
"regex": "[a-z]",
"replacement": ""
},
{
"function": "replace",
"regex": " ",
"replacement": ""
}
]
}
}
Thanks again for your help!
I've just tested it and it works perfectly, thank you.