I’m trying to use the findText()
function of the DocumentApp
class to get the position of some text inside a Google Docs. To do so, I’m using a Regex (RE2) expression. I want it to find the following sequences: $$anyCharacterHere$$
; basically anything enclosed in between $$ … $$. As there might be more than one of these sequences, we have to tell the regex to match any sequence of this type without any “$” inside.
I’ve tried using the following:
const re2 = new RegExp("\$\$.*(?!\$)\$\$");
let range = docBody.findText(re2)
but it says that this is an invalid expression. I tried changing the backslashes and that kind of things, but couldn’t get any further.
The goal I want to achieve is, for example, in this text:
Thi is a $$text$$ to show an $example$$ of how the $$regex$$ $$$hould$$ work.
the regex should find: $$text$$ and $$regex$$.