Using Compile Replacements with Regular Expressions

trying to include LaTeX equations conveniently into Scrivener with MMD, I was playing around with the project replacements in the compile menu. The idea is to use for example
$x = 1$
in Scrivener, which should compile to

in MMD and then be parsed back to
$x = 1$
in LaTeX.

After a bit of fiddling with, I found out that I need to replace
$([^$]*)$ with in order to make it work. Compiling Scrivener to MMD I do get
which looks like the regular expression replacement is applied twice. Is this some kind of bug or are there different ways of implementing RegEx as it is working fine on the site mentioned above?

Merry Xmas,

By the way: I posted not in the MMD section of the forum, as this also happens when compiling to plain text. So it seems to be a Scrivener issue.

The search pattern is all right, it looks there may be a small recursion problem though when generating a string that would itself match the original pattern again. Since it stops at only two repetitions it may only be that the replacement is being applied twice for some reason, causing the second layer of HTML escapes to be added. You would get the same result by running the same regex in the regular Cmd-F search panel twice on the same string. I’ll make sure this is on the list to look at after the holiday. For now it may be best to use another delimiter in the editor. If and when the bug can be fixed, you can then run a global search and replace in the project to go back to a more familiar approach if you wish.

Thanks for the clear answer. I switched back to Scrivener syntax for replacing stuff.

I tried $$@$ which does not work, but $$@ $ (additional whitespace) does the job.