thwippp
2/7/2017 - 10:29 PM

Replace text and make it bold

Replace text and make it bold

 function docReplace(input, output) {
  var re = new RegExp(output,"g");
  var body = DocumentApp.getActiveDocument().getBody();
  body.replaceText(input, output);

  var text = body.getText();
  var index;
  while(true){
    index = re.exec(text)
    if(index == null){break}
    body.editAsText().setBold(index.index, output.length + index.index, true);
  }
}