How can I add the first name of an author and the pipe character (|) to the citation key generator?


I would like to generate a specific citation key. Let’s assume that I have an item in my library for a book titled “A random title” written on 2022 by Foo Bar. Also, let’s assume that a year later, they make a new edition with the help of a different author. I will call this new author Boo Var. I add this to my library too. These items would get these citekeys:

  1. foo|2022|art
  2. foo+|2023|art

So far, I have the following to generate this kind of citekeys: [authors1:lower:regex("etal","+")][YEAR][TITLE:lower:abbr]. However, [authorsN] gives me the last name, not the first name. Another issue is that there doesn’t seem to be a way to add the pipe symbol (|).

I couldn’t find anything about this in the documentation. So, could you help me to accomplish this? Thanks in advance.

Oh, and in case it is of any help, I would like to explain why I want to add these things. I have an easier time remembering an author’s first name. Plus, I’m not keen on how citation styles prefer to use a person’s last name over the first name. Then, the pipes are so that if an author or title has numbers, I can still tell the year apart.

Hey Annabella :slight_smile:

  1. With regard to the pipe symbol, you can add it like this:


    The pipe symbol is used in regex as a OR operand so you have to put a backslash in front. Keep in mind, that special non-standard characters might also lead to unintended consequences, when using LaTeX or other Programs. If you want to be on the safe side, use standard characters and numbers only. The pipe symbol | apparently is used in Latex math mode, so you would need to replace | with \textbar, whenever you want to cite something within mathmode (LaTeX/Special Characters - Wikibooks, open books for an open world). Your operating system also will have a list of symbols that cannot be used to name files, so if you at one point think of using the citationkey to name your attached files, plan ahead.

  2. I don’t know how to add the first name, but i think you would have to create a new group [examplegroup] via regex within Jabref code. Could be easier than we think, as there already is a group that uses first names: [authForeIni], albeit only in abbreviated form. If somebody could identify the lines of code within Jabref, we then could duplicate this code and then remove the part that creates the abbreviation.

Thanks Thilote for commenting!

Considering how troublesome the pipe symbol can be, what about looking at this from a different angle? I was thinking of a modifier that strips out numeric characters from the other fields. The listed modifiers in the documentation don’t include something like this. Do you have any idea if there is but undocumented?

As for adding the first name, that sounds good. Alas, I know nothing about coding. Hopefully someone who does could chime in. That’d be much appreciated.

I have a new question, by the way. It’s relevant to this. I hope it’s alright to bring it up. Some webpages lack a date of publication. So, I thought of using the accessed date instead. I came up with this: [YEAR:([URLDATE])] . Problem is that the accessed date includes the month and day number. For example, “Dec. 31, 2020.” Regex is of no use here because it seems to only apply to [YEAR] . How could I make it so?

Along the same lines, how could I shorten the number of modifiers I would have to use? Because I would have to do this for all the months and day numbers. For example, [URLDATE:regex("Jan.",""):regex("Feb.",""):regex("Mar.","")] and so on. Is it possible to shorten this in some way?

Could you test, if this works for you?

[authors1:lower:regex("etal","\+"):regex("[0-9]", "")]\|[YEAR:([URLDATE:truncate4])]\|[TITLE:lower:abbr]

I was thinking of using a Lookahead assertion x(?=y) together with matching non-word boundaries \B for the URLDATE, but the above should work, as long as you enter all your dates in the following format:


Example for your bib-file:

urldate = {2020-12-31},

This form would conform to Biblatex and ISO Standards and as you can see is much easier to work with than Dec. 31, 2020.

If you want to get deeper into (RegEx-) search expressions, i can recommend these websites:

This is perfect! Thank you so much.

I removed the pipe symbol, though. I’d like to be on the safer side. Besides, without numbers neither in the author nor the title, I don’t need to “isolate” the year. Also, I’m keeping the title as it is without the regex because I haven’t come across a title with a number at the beginning. But if I ever do, I’ll know what to do.

So, this pretty much solves the issue with isolating the year and using the access date in its place depending on the context. I’ll see what I can do about the author thingie. If I somehow manage to solve it myself, I’ll make sure to post here.

Thanks for the resources, by the way. Much appreciated.

1 Like

Awesome! :smiley:

Uh, i just noticed a typo: [URLDATE:truncate4] instead of [URLDATE::truncate4] should be correct.

With regard to the author thingy, i found this: regex - Regular expression for first and last name - Stack Overflow
oh and i also found this regex tester: Url - Regex Tester/Debugger
but … after having a look at it, i decided not to go too deep there xD If you do and find the solution, posting it here would be great, indeed. Might bring happiness to some people :slight_smile:

I did it! Here’s the resulting citation key generator:

[AUTHOR:regex(" ([A-z]|[0-9])*",""):lower][authors1:regex("EtAl","+"):regex("([A-z]|[0-9])","")].[YEAR:([URLDATE:truncate4])].[TITLE:lower:abbr]

With this, I get nice citation keys such as shadow+.1999.sthabotulf.

Beware, I’m a beginner with regex stuff, so there’s stuff I don’t understand and it might be possible to make this simpler or better. Feel free to correct me if I’m wrong or if there’s a better way.

I’ll try to explain what’s going on with the regex expressions.

[AUTHOR:regex(" ([A-z]|[0-9])*",""):lower]

regex(" ([A-z]|[0-9])*","") will replace any letters or numbers after the first white space by nothing. It also seems to target whitespaces. Not so sure why. So if you have “Sh4dow the Hedgehog” in the author field, it will become “Sh4dow” .


regex("EtAl","+") replaces EtAl by the plus sign (+). Then, regex("([A-z]|[0-9])","") removes any letters or numbers. So all you get is the plus sign. Of course, this happens only if there are two authors or more.

The reason I decided to keep numbers is because I’ve wrapped the year with a period (.). The period doesn’t seem to create any issues, so it should be fine.

Thank you so much Thilote for your help!