# Regex for key (a,b,c)

**URL:** <https://discourse.jabref.org/t/regex-for-key-a-b-c/3888>\
**Category:** Help\
**Created:** [July 23, 2023, 2:24am UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888 "2023-07-23T02:24:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![melTr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/meltr/32/277_2.png) [@melTr](https://discourse.jabref.org/u/melTr)\
**Post date:** [July 23, 2023, 2:24am UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/1 "2023-07-23T02:24:19Z")

</div>

Hi  
I’m struggling to create my bibkey. I don’t like how the a (or b, c) get added when we have duplicate keys. I want to at least add a “\_” but I’m unable apply a regex replace to the duplicate (since it’s not a field by itself). I tried the general [replacement](https://docs.jabref.org/setup/citationkeypatterns#replace-via-regular-expression) in preferences :  
a$ → \_a  
but it didn’t work.  
Example : Authora should give Author\_a  
How can I achieve this?  
Thanks  
Mel

---

<div class="post-metadata">

**Author:** ![ThiloteE](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/thilotee/32/1008_2.png) [@ThiloteE](https://discourse.jabref.org/u/ThiloteE)\
**Post date:** [July 23, 2023, 9:43am UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/2 "2023-07-23T09:43:21Z")

</div>

While `_` is not a forbidden character in Java RegEx (See here: [Searching within the library - JabRef](https://docs.jabref.org/finding-sorting-and-cleaning-entries/search#searching-for-strings-with-a-special-character-usd-or-+.)), `_` is a [special character in LaTeX](https://en.wikibooks.org/wiki/LaTeX/Special_Characters) and therefore has to be escaped with a backslash like this: `\_`. So i would avoid to use this as your bibkey if you ever want to export this entry to a LaTeX document.

While looking this up, I think i found a typo in our documentation. `_` should probably be removed from the following paragraph: [Searching within the library - JabRef](https://docs.jabref.org/finding-sorting-and-cleaning-entries/search#searching-for-strings-with-double-quotation-marks)

---

<div class="post-metadata">

**Author:** ![ThiloteE](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/thilotee/32/1008_2.png) [@ThiloteE](https://discourse.jabref.org/u/ThiloteE)\
**Post date:** [July 23, 2023, 10:02am UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/3 "2023-07-23T10:02:32Z")

</div>

If you really want to, i think you probably want something like this (untested):

`:regex("[author][year].+", "[author][year]\_.+")`

- `.` means: any character
- `+` means: one or more times

---

<div class="post-metadata">

**Author:** ![melTr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/meltr/32/277_2.png) [@melTr](https://discourse.jabref.org/u/melTr)\
**Post date:** [July 23, 2023, 9:52pm UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/4 "2023-07-23T21:52:25Z")

</div>

Hi.  
Thanks. However for some reason any regex would be replaced. It just throw : `regex[author][year].+[author][year]_.+`  
I tried some sampler patterns, without success.  
I kind of give up… I’m not sure at all global regex are working on a,b,c added. I tried a simple a → z replacement and only “a” letters got changed, not the added duplicate a.  
Mel

---

<div class="post-metadata">

**Author:** ![ThiloteE](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/thilotee/32/1008_2.png) [@ThiloteE](https://discourse.jabref.org/u/ThiloteE)\
**Post date:** [July 23, 2023, 10:44pm UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/5 "2023-07-23T22:44:46Z")

</div>

hmm, you could just try to avoid duplicates by using a very complex citationkey pattern or simply using the ISBN or DOI, if there is any.

---

<div class="post-metadata">

**Author:** ![Siedlerchr](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/siedlerchr/32/216_2.png) [@Siedlerchr](https://discourse.jabref.org/u/Siedlerchr)\
**Post date:** [July 26, 2023, 10:09am UTC](https://discourse.jabref.org/t/regex-for-key-a-b-c/3888/6 "2023-07-26T10:09:47Z")

</div>

I think underscore is just listed as unwanted character, you can check that in the preferences
