I am building a mail merge type function in google docs scripts. I have chosen to use square brackets to delimit the fields. I have noticed replaceText does strange things when matching for strings with square brackets, as demonstrated by the following test function.
function testReplace()
{
var outputDoc = DocumentApp.create("testReplace");
outputDoc.appendParagraph('Hello [World]');
var body = outputDoc.getActiveSection();
body.replaceText('[World]', 'There');
// Document content:
// HeThereThereThere [ThereThereThereThereThere]
// I would have expected:
// Hello There
}
Can anyone explain what is going on? Thanks in Advance.