regex - Google Apps Script text formatting with special characters -
i trying alter formatting datatype declarations in google doc file this:
[char(10)]
to this:
i using regex identify instances this:
var fdt = new regexp('\[varchar|char|numeric|bit|date|number|decimal[(0-9,)]+?\]','gi'); while (match= fdt.exec(bodyelement.astext().gettext())){ ... } it correctly finds datatypes want process. however, code format fails. think because contains both [] , ().
i need find instances of match , using within while loop:
var sr = bodyelement.findtext(match[0]); while (sr !== null){ var te = sr.getelement(); var tet = te.astext(); tet.setattributes(sr.getstartoffset(),sr.getendoffsetinclusive(),formatstyle); sr = bodyelement.findtext(match[0],sr); } this isn't correctly stepping through total body looking matched text. work if utilize word 'char', char in charring updated.
how create work?
update:
putting them together:
/* * standard variables */ var formatstyle = {}; formatstyle[documentapp.attribute.font_family]=documentapp.fontfamily.calibri; formatstyle[documentapp.attribute.foreground_color]='#ff6600'; formatstyle[documentapp.attribute.font_size]='11'; formatstyle[documentapp.attribute.italic]=true; function finddatatype(){ var fdt = new regexp('\[varchar|char|numeric|bit|date|number|decimal[(0-9,)]+?\]','gi'); while (match= fdt.exec(bodyelement.astext().gettext())){ var sr = bodyelement.findtext(match[0]); while (sr !== null){ var te = sr.getelement(); var tet = te.astext(); tet.setattributes(sr.getstartoffset(),sr.getendoffsetinclusive(),formatstyle); sr = bodyelement.findtext(match[0],sr); } } regex google-apps-script
No comments:
Post a Comment