1

Using Google apps script, in a google text document (i.e. just a regular documenet), I would like to convert the following string

{ some text | footnote | link }

to

some text

with a footnote attached, and a link added to the text.

So it would be something like this:

var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var myRegexp = new RegExp('\{(.*)\|(.*)\|(.*)\}','g');
body.replaceText(myRegexp, "$1");

followed by adding the footnote and link to the result. I can't get the replaceText to work (and there's a note about capture group support in the documentation).

Would really appreciate some help with a complete recipe on how to do this!

  • Hi there, thanks for the question. ReplaceText does work, but I can't get the capture groups to work, i.e. there's no text in $1, $2, etc. Work around: What's possible is to match the whole string you're interested in, and then do a javascript regexp replace on it (using $1, $2, etc as needed), to get the new string, and then go back to the document to replace. It just seems that capture groups are not implemented in Google Apps script yet. – user55143 Jun 9 '14 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.