Broken regexp replace in TeXstudio macros

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?

• maybe you have to mask the `\ ` in the replace pattern as `\\ ` (which would be very uncommon). Or it doesn't use `\1` `\2` and instead `\$1` `\$2` etc. check the manual for the replacement command – musicman Oct 13 '15 at 7:15
• @musicman The problem is - numbered matches aren't even mentioned in manual:texstudio.sourceforge.net/manual/current/… . And I've tried \$1 (since these are supposed to be js-macros), but it puts '\$1' literally both in macro and UI, but \1 does the substitution in UI command. – The_Keeper Oct 13 '15 at 8:39
• @musicman hm, changing \ to \\ seems to work, thanks – The_Keeper Oct 13 '15 at 8:48

``````%SCRIPT
``````Here goes some \mbox{text}, more \mbox{text} and some more \mbox{text}.