JabRef / jabref

Graphical Java application for managing BibTeX and biblatex (.bib) databases
https://devdocs.jabref.org
MIT License
3.66k stars 2.59k forks source link

Any regex in citation key generator produces empty field #7128

Closed Linguista closed 4 years ago

Linguista commented 4 years ago

JabRef version 5.1 on Kubuntu 20.04

Any use of a regex in Options > Preferences > Citation key generator > Key Patterns > Key Pattern produces an empty field.

Steps to reproduce the behavior:

  1. Start with any key pattern, e.g.[authEtAl][year][shorttitle:capitalize]
  2. Add a regex to a field, e.g. [authEtAl][year][shorttitle:capitalize:regex("Del", "")]
  3. Hit enter, save preferences.
  4. Open a bibliographic entry.
  5. Hit the Generate button.

In this case, the generated field consists only of authEtAl and year. shorttitle is empty.

k3KAW8Pnf7mkmdSMPHz27 commented 4 years ago

Hi @Linguista, There were an earlier version with a bug in the regex modifier that occurred with space after , and the empty replacement "". Could you try regex("Del","_") instead?

You can try a more recent development build at https://builds.jabref.org/master/ , just make sure to backup your library beforehand.

Linguista commented 4 years ago

Hi @Linguista, There were an earlier version with a bug in the regex modifier that occurred with space after , and the empty replacement "". Could you try regex("Del","_") instead?

Thanks very much -- you hit the nail on the head. Both the space between the regex fields and an empty replacement string break the citation generation on any field that has them. I can avoid the space, but adding garbage strings to citation keys obviously isn't idea.

Fortunately, the latest dev version fixes the error.

If I may ask a follow-up question, there seems to be no way to add stop/function words to the built-in English-only list of them that JabRef comes with. So I'm trying to do the same thing with the regexes in the citation key generator. But it seems that the non-word code, \W, doesn't work. Nor does the escaped version, \\W. Is this wrong, or is this a bug?

k3KAW8Pnf7mkmdSMPHz27 commented 4 years ago

but adding garbage strings to citation keys obviously isn't idea.

While not ideal, if you are worried about using the dev version you can use the "Replace (regular expression)" feature to later remove the garbage string.

Nor does the escaped version, \\W. Is this wrong, or is this a bug?

\\W appears to works for me. Could you give an example of how you are using it? I'd not expect it to be used it for that purpose. Does something along the lines of (\\bword\\b) work? (example is from https://www.regular-expressions.info/wordboundaries.html)

k3KAW8Pnf7mkmdSMPHz27 commented 4 years ago

there seems to be no way to add stop/function words to the built-in English-only list of them that JabRef comes with.

I don't think there is, but it could perhaps be an idea for a new issue with this as a feature request? (I have never used JabRef for non-english citations, I don't know how useful this is to others)

Linguista commented 4 years ago

Nor does the escaped version, \\W. Is this wrong, or is this a bug?

\\W appears to works for me. Could you give an example of how you are using it? I'd not expect it to be used it for that purpose. Does something along the lines of (\\bword\\b) work?

Yes! \\b" is exactly what I needed... with one addition. I'm searching on lowercase words but I had thecapitalize` command right before it, which was making everything fail!

Duh!

Thanks so much for your help.

Siedlerchr commented 4 years ago

So if I understood this correctly, this issue is solved in the latest development version and you also have a custom solution.