I'm trying to do a search and replace in a Google Doc using a Google Script. A straight text search and replace like available through the web interface.
The source doc contains [schoolname] as a placemarker and I want to make a copy of that original, then search and replace [schoolname] in the new document.
I tried replaceText("([schoolname])","sometext") after reading this thread: How to use method replaceText(searchPattern, replacement) in documents Service/ text Class
I double checked the regex through http://www.regexr.com/ to no avail
Should I be using some alternative to replaceText() or just fix the regex somehow? Thanks in advance.
Edit: code segment
var newfile = sourcefile.makeCopy();
newfile.setName(sourcefile.getName().replace("[schoolname]","replacementtext"));
var newdoc = DocumentApp.openById(newfile.getId());
var paras = newdoc.getBody().getParagraphs();
newdoc.getBody().replaceText("(\[schoolname\])","replacementtext");