How does {replace} work?

I've tried making a snippet to find/replace a number of strings in a Google doc but it didn't work.

Could someone kindly explain how I could do this. I'm sure I'm missing some important detail.


Here's a quick example:

{=replace("I like dogs, do you like dogs?", "dogs", "cats")}

Note also that in your Google docs example you are replacing "\n". The backslash is a special character that needs to be escaped in Text Blaze strings (and in most other programming languages too!), you can do that by placing another backslash in front of it:

{=replace("Line1\\nLine2", "\\n", "\n")}

The "\\n" means match a backslash followed by a newline as backslash-backslash is the special sequence to represent a single backslash. The "\n" means replace it with a newline as backslash-n is the special sequence to represent newlines.

Yes, that works fine. But I want to use it with formtext to replace text strings in a Google doc. Can it be done? Because I haven't managed :slight_smile:

What is your snippet? If you are loading contents with {urlload}, you could want to include the replace call in your callback. e.g. something like done=(res) -> ["text"=replace(res, "dog", "cat")]

Ah, so it's not enough to have a simple replace snippet with formtext, and run it in the Google doc! OK, so I'll try it with urlload then.

Thanks for putting up with my incessant questions lol.