# Replace double quotes using the Replace() export formatter

**URL:** https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697
**Category:** Help
**Created:** [January 3, 2023, 9:35pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697 "2023-01-03T21:35:38Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![pedroracine](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/pedroracine/32/38_2.png) [@pedroracine](https://discourse.jabref.org/u/pedroracine)
#### Post date: [January 3, 2023, 9:35pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/1 "2023-01-03T21:35:38Z")

</div>

Hi,

I commonly use the Replace() export formatter but I can’t get it to find and replace double quotes.

To reproduce:

1-Change the “Customized preview style” to:

\format[Replace(“\”,")]{\author}

2-Add a double quote (") to the AUTHOR field of any entry.

3-The preview show the preview code instead of the string without double quote.

I tried to add backslashes to better escape the double quote in the preview quote without success:

\format[Replace(“\\”,“)]{\author}  
\format[Replace(”\\\“,”)]{\author}  
…

Any idea?

Thanks,

Pierre

---

<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: [January 3, 2023, 10:07pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/2 "2023-01-03T22:07:35Z")

</div>

have you tried

`\format[Replace(“”,“)]{\author}`  
or `\format[Replace(\“\”,\“)]{\author}`  
or `\format[Replace(\\“\\”,\\“)]{\author}`

?

---

<div class="post-metadata">

### Author: ![pedroracine](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/pedroracine/32/38_2.png) [@pedroracine](https://discourse.jabref.org/u/pedroracine)
#### Post date: [January 4, 2023, 3:04pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/3 "2023-01-04T15:04:22Z")

</div>

Just tried and no success either.

---

<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: [January 4, 2023, 4:21pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/4 "2023-01-04T16:21:55Z")

</div>

Hi,

that was a tricky one. I only figured this out while having the debugger opened at the same time to see what comes down to the method in the end. Had to do something with the number of quotes etc.

`\format[Replace("\",)]{\author}`

Maybe you can add that as an example to the docs for the Replace formatter:

> **[Custom export filters](https://docs.jabref.org/collaborative-work/export/customexports#built-in-export-formatters)**

Edit// If you have modified the preview style you need to switch back and forth to the entry. Otherwise, it’s not updated correctly

---

<div class="post-metadata">

### Author: ![pedroracine](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/pedroracine/32/38_2.png) [@pedroracine](https://discourse.jabref.org/u/pedroracine)
#### Post date: [January 4, 2023, 5:03pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/5 "2023-01-04T17:03:22Z")

</div>

Thanks,

That works when \" is the only rule in the regex but as soon as you try to add, for example, other matching characters:

> \format[Replace("(x|"),)]{\author}

it fails.

I guess the proper solution would be to get Replace to unescape " properly.

---

<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: [January 4, 2023, 5:29pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/6 "2023-01-04T17:29:02Z")

</div>

Hi,

hm from what I saw there are two separate issues. One is the parsing of the expression itself (seems to fail if you only have a single quote `"` and the second one is the parsing of the argument string:

The argument parsing happens here for Replace e.g. For The Replace it needs two parts. It seems like it does check for some escaping stuff, but I did not take a deeper look. Maybe this helps you:

> <https://github.com/JabRef/jabref/blob/06771c8dc482015b5e9693b1f7a28e4b0830e079/src/main/java/org/jabref/logic/layout/AbstractParamLayoutFormatter.java#L17-L24>

---

<div class="post-metadata">

### Author: ![pedroracine](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/pedroracine/32/38_2.png) [@pedroracine](https://discourse.jabref.org/u/pedroracine)
#### Post date: [January 4, 2023, 6:53pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/7 "2023-01-04T18:53:23Z")

</div>

I’m not able to test but I think:

> if ((arg.charAt(i) != ‘,’) && (arg.charAt(i) != ‘"’)) {

should be replaced by:

> if (!((arg.charAt(i) == ‘,’) || ((arg.charAt(i) == ‘"’) && (i == arg.length() - 1)))) {

i.e. Keep the escaped double quotes escaped unless it is the last character.

---

<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: [January 4, 2023, 8:22pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/8 "2023-01-04T20:22:56Z")

</div>

@pedroracine Thanks for the code, I made a PR with the changes so you can test it

Download version:

> **[index - powered by h5ai v0.29.0 (https://larsjung.de/h5ai/)](https://builds.jabref.org/pull/9528/merge/)**
>
> index - powered by h5ai v0.29.0 (https://larsjung.de/h5ai/)

> <https://github.com/JabRef/jabref/pull/9528>
>
> Refs https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-expo…rt-formatter/3697/7
> 
> \<!-- 
> Describe the changes you have made here: what, why, ... 
> Link issues that are fixed, e.g. "Fixes #333".
> If you fixed a koppor issue, link it, e.g. "Fixes https://github.com/koppor/jabref/issues/47".
> The title of the PR must not reference an issue, because GitHub does not support autolinking there.
> \--\>
> 
> 
> \<!-- 
> \- Go through the list below. Please don't remove any items.
> \- \[x\] done; \[\] not done / not applicable
> \--\>
> 
> \- \[\] Change in \`CHANGELOG.md\` described in a way that is understandable for the average user (if applicable)
> \- \[\] Tests created for changes (if applicable)
> \- \[\] Manually tested changed features in running JabRef (always required)
> \- \[\] Screenshots added in PR description (for UI changes)
> \- \[\] \[Checked developer's documentation\](https://devdocs.jabref.org/): Is the information available and up to date? If not, I outlined it in this pull request.
> \- \[\] \[Checked documentation\](https://docs.jabref.org/): Is the information available and up to date? If not, I created an issue at \<https://github.com/JabRef/user-documentation/issues\> or, even better, I submitted a pull request to the documentation repository.

(You can open the PR and then just somewhere press the . dot key and github will open an online editor)

---

<div class="post-metadata">

### Author: ![pedroracine](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.jabref.org/pedroracine/32/38_2.png) [@pedroracine](https://discourse.jabref.org/u/pedroracine)
#### Post date: [January 4, 2023, 9:21pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/9 "2023-01-04T21:21:56Z")

</div>

Unfortunately no success ☹

---

<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: [January 6, 2023, 7:48pm UTC](https://discourse.jabref.org/t/replace-double-quotes-using-the-replace-export-formatter/3697/10 "2023-01-06T19:48:09Z")

</div>

Hm, this is bad. Can you give a sample bib entry with how it looks before the Replace and after the replacement (e.g. what is the expected outcome? Then I can try to write a test for this function.
