Compile mixes my RegEx


my intention is to replace MMD reference tags – which I normally need for LaTex output – with EndNote readable strings, because I occasionally need to have MS Word and EndNote output.

During the compile process there seems to be an error with RegEx. I have checked my code with the RegExRX App, so the code seems to be fine:

Search Pattern:

Replace Pattern:

Source Text:
[S. 15f][#Martens2009;] blablabla [S. 54][#Steenblock2011a;]

Replaced Text :
{Martens2009@ 15f@author-year} blablabla {Steenblock2011a@ 54@author-year}

But if I run compile in Scrivener to get an docx output, then I get as Replaced Text:

{Steenblock2011@ 15f][#Martens2009;] blablabla [S. 54@author-year}

furthermore with other Source Text like [S. 73][#kant_2010a;] it also works fine in Scrivener.

It also works if I either export [S. 15f][#Martens2009;] or [S. 54][#Steenblock2011a;] but not both.

Any idea?


I can confirm the regex is doing what it is supposed to, tested with an PCRE compatible online tester here:

What you are saying is that when [any?] TWO references are in the same line there is a problem, which isn’t the case with only one? Does this happen per line, per document or what?

Edit: I tested this in a very simple Scrivener 3 project and cannot reproduce, given this input:

As we see [S. 15f][#Martens2009;] blablabla [S. 54][#Steenblock2011a;] was very clear… Also see [S. 73][#kant_2010a;] for more…

And compiled to plain text I get:

As we see {Martens2009@ 15f@author-year} blablabla {Steenblock2011a@ 54@author-year} was very clear… Also see {kant_2010a@ 73@author-year} for more…

If the three codes are in the same document in crashes for [S. 15f][#Martens2009;] and [S. 54][#Steenblock2011a;] but the output of [S. 73][#kant_2010a;] is fine. I’m using Scrivener 2.

… could there be a conflict between other RegEx expressions I am using during the compile prozess, too? … I will check this

hmm I do not know. I have re-written the code and updated my Search Pattern to


And Replace Pattern to


wich seems to be more robust. But I do not know why.

Yes, I think I had to many different RegEx Expressions in my Compile Code. Simplifying things seems to be it.

Glad you got it fixed!