Question

Does anyone know if google-apps-script's replaceText function internally uses javascript's String.replace function?

The reason I'm asking is that google-apps-script's replaceText function's syntax is:

replaceText(searchPattern, replacement)

Where as javascript's String.replace function's syntax is:

str.replace(regexp|substr, newSubStr|function[,   flags]);

I.e., the replacement can be either a string or a function.

All in all, can I use function as the replacement in google-apps-script's replaceText function?

Was it helpful?

Solution

No. it does not. The replacement has to be a string. Another important difference is that even though searchPattern is a string, it will create a regexp to do the matching. It's not like String.replace where you can provide a literal string or a regexp.

You could write your own replaceText function that uses String.replace "internally". You'd just have to loop the entire document structure looking for Text blocks and do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top