Unexpected extra spaces in filenames when using custom filename format in Zotero 7
Description:
I'm using Zotero 7 on Linux and have set up a custom filename format for renaming PDF files. The format is designed to follow these rules:
1. Include the family name and initialized given name of the first creator, followed by a dot.
2. Include the year, followed by a dot.
3. Include the item type (for books) or journal abbreviation (for other types), followed by a dot.
4. Replace Windows/Linux forbidden characters in the filename:
- Replace <>:/\| with "-"
- Remove "?*
- Replace all spaces with "_"
Current "Customize Filename Format":
```
{{ creators name="family-given" initialize="given" max="1" name-part-separator="" }}
{{ year suffix="." }}
{{ if {{ itemType == "book" }} }}
{{ itemType suffix="." }}
{{ else }}
{{ journalAbbreviation suffix="." }}
{{ endif }}
{{ if {{ title match="[<>:/\|]" }} }}
{{ title replaceFrom="(<|>|:|/|\\|\|)" replaceTo="-" regexOpts="g" truncate="255" }}
{{ endif }}
{{ if {{title match="["?*]"}} }}
{{ title replaceFrom="("|?|*)" replaceTo="" regexOpts="g" truncate="255" }}
{{ endif }}
{{ if {{title match=" "}} }}
{{ title replaceFrom="(\s+)" replaceTo="_" regexOpts="g" truncate="255" }}
{{ endif }}
```
Issue:
The resulting filenames contain unexpected extra spaces. For example:
```
AuthorB.2024. book. The_Book_Title.pdf
```
There are extra spaces before "book" and "The" in the filename.
Questions:
1. How can I modify the format expression to eliminate these extra spaces?
2. Are there any errors in the regex expressions that need to be corrected?
Thank you.
BTW, I noticed that the 'Customize Filename Format' shared earlier has some issues. It reproduces multiple titles if more than two conditions are met. I also found the cause of the extra spaces—they’re due to leading spaces at the beginning of each line. Since Zotero 7 can now handle special characters in filenames, the format can be rewritten as follows:
Current "Customize Filename Format":
```
{{ creators name="family-given" initialize="given" max="1" name-part-separator="" }}
{{ year suffix="." }}
{{ if {{ itemType == "book" }} }}
{{ itemType suffix="." }}
{{ else }}
{{ journalAbbreviation suffix="." }}
{{ endif }}
{{ title replaceFrom="(\s+)" replaceTo="_" regexOpts="g" truncate="255" }}
```