Found a lot of information, where people say it should work like this:
var id = '/*doc ID here*/';
var doc = DocumentApp.openById(id);
var body = doc.getBody();
var word = 'tototo'
var tempword = 'blablabla';
body.replaceText("\\b"+word+"\\b", tempword);
But it is not working.
Thу full idea is to find every word LALALA and make it a link, but don't make a link from words LALALAL or ALALALA etc.
function addLinks(word, siteurl) {
var id = '/*doc ID here*/';
var doc = DocumentApp.openById(id);
var body = doc.getBody();
var tempword = 'ASDFDSGDDKDSL2';
var element = body.findText(word);
// var element = body.findText("\\b"+word+"\\b");
while(element) {
var start = element.getStartOffset();
var text = element.getElement().asText();
text.replaceText("\\b"+word+"\\b", tempword);
text.setLinkUrl(start, start+tempword.length-1, siteurl);
var element = body.findText(word);
}
body.replaceText(tempword, word);
}
addLinks('LALALA', 'example.com');
But it makes only one link and not from 1 word as needed, but from 16 letters...