Created
May 22, 2017 11:10
-
-
Save 5argon/dd9ed463162c4f2da216298ea781afc6 to your computer and use it in GitHub Desktop.
How to format an entire document using RegEx in Google Docs add-on. It will bold my name in string like "5argon : Hello World!"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatInkVN() { | |
var body = DocumentApp.getActiveDocument().getBody(); | |
//all text! | |
var allText = body.editAsText(); | |
var regexString = "^.*[ ]:[ ]"; | |
var rangeElement = allText.findText(regexString); | |
while (rangeElement != null) { | |
var matchedText = rangeElement.getElement().asText(); | |
var begin = rangeElement.getStartOffset(); | |
var end = rangeElement.getEndOffsetInclusive(); | |
Logger.log(begin + " " + end); | |
matchedText.setBold(false); //matchedText is the entire line, I want to reset the line first | |
matchedText.setBold(begin, end, true); //Then I bold only the part that RegEx matches. | |
rangeElement = allText.findText(regexString, rangeElement); //continue from previous point | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment