Here's a problem I've encountered when I tried make a script in TeXstudio with several replace queries. Suppose I have some text:
Here goes some text, more text and some more text.
And when I apply this macro
%SCRIPT
editor.replace(/\s(text)([\.,\s])/g, '\mbox{\1}\2')
to it, the resulting text is messed up:
(in a text field it looks like this)

In the meantime everything works fine when the same regexp is called from GUI Replace menu:
Here goes some \mbox{text}, more \mbox{text} and some more \mbox{text}.
The text in UTF-8 encoding. Is that behaviour a bug, or my script lacks something important?

\in the replace pattern as\\(which would be very uncommon). Or it doesn't use\1\2and instead$1$2etc. check the manual for the replacement command – musicman Oct 13 '15 at 07:15