Im trying to run a very basic Google Script on a document.
docBody = docBody.replaceText(searchStr, replaceStr);
It works perfectly when the searchStr = ‘Name’ for example, but when I try to replace ‘[Name]’ the script hangs and produces garbage in the document. I realise that the searchStr parameter is a regular expression and I have tried :
\[Name\]
/\[Name\]/g
(\[Name\])
All with no success…
Any suggestions?
If you’re doing
then that should work, without slashes, without modifiers, without groups. If you’re using double-quotes, make sure to double-escape: