Replace double quotes using the Replace() export formatter

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

have you tried

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

?

Just tried and no success either.

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:

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

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.

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:

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.

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

Download version:

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

Unfortunately no success :frowning:

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.