Is it possible to capture whole fields for lookahead and lookbehind RegEx in keygenerator?

I tried some stuff, but it does not work.

e.g.

(?<=[KEYWORDS])123

Translation: Match 123 only, if there is no data within the keywords field.

This is the resulting entry from generating a key with the above pattern:

@Article{<123,
  title = {333},
}

The citationkey turns out to be <123.

So this clearly is not the result i was expecting.

Is there a special RegEx that users can use and that would allow me to do this, or would Jabref need to add some code that would make this work first?

Documentation about regular expressions for Java: Pattern (Java Platform SE 8 )
Documentation about Conditional RegEx: Conditional Regular Expressions—from 101 to Advanced

Yes, it is possible. There are several ways to produce your intended citation key, with or without a lookaround expression. One way is to replace a blank keywords field with 123. If the beginning of the field is adjacent to the end, then the field is blank.

[KEYWORDS:regex("^$","123")]

To use a lookaround expression on the whole field, first match the entire field with ^.* then add a positive or negative lookbehind to search for the string of interest. Remember to add .* after the target string or you will only get a match if the target is at the end of the field. This may not be very efficient, but it works.

This example generates the citation key yes if the keywords field contains mykeyword.

[KEYWORDS:regex("^.*$(?<=mykeyword.*)","yes")]

Here is a variation that generates alternative keys based on mutually exclusive regex expressions, and a blank key in case of no match.

  • yes if keywords contains mykeyword
  • no if keywords is blank

[KEYWORDS:regex("^.*$(?<=mykeyword.*)","yes"):regex("^$","no")]

1 Like

Thank you so much! I will try it one of these days. Am on a trip right now.