function searchAndColorInRed() {
var doc = DocumentApp.getActiveDocument();
var textToHighlight = new RegExp('\(\d{0,4}\)');
var highlightStyle = {};
highlightStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#FF0000';
var paras = doc.getParagraphs();
var textLocation = {};
var i;
for (i=0; i<paras.length; ++i) {
textLocation = paras[i].findText(textToHighlight);
if (textLocation != null && textLocation.getStartOffset() != -1) {
textLocation.getElement().setAttributes(textLocation.getStartOffset(),textLocation.getEndOffsetInclusive(), highlightStyle);
}
}
};
Got this function to search for numbers in parentheses like (6406) however the coloration won't work.. I have no ideas why, can someone help me please ?