I'm trying to import my notes from Kindle into a Google Doc (you can view it here), and I have a document in which I want to strip out all of the occurrences of the following text (including the line break):
Read more at location 6567 • Delete this highlight
Add a note
I came up with the following search pattern and tested it on this google sheet to make sure my regex syntax works:
"Read more at location (\d*) • Delete this highlight\nAdd a note"
Then I created a google apps script, and have it load in my document:
function onOpen() {
DocumentApp.getUi() // Or DocumentApp or FormApp.
.createMenu('AdvancedFind&Replace')
.addItem('Remove Kindle HTML', 'findAndReplace')
.addToUi();
}
// In-Document Find and Replace
function findAndReplace() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText("Read more at location (\d*) • Delete this highlight\nAdd a note", "");
}
However, when I run it, it doesn't replace the text. I think it's a problem with the REGEX, because when I run this code instead, it works:
function replaceBat() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText("BBat", "BBAat REPLACEMENT SUCCESSFUL");
}
Any help would be greatly appreciated, thanks!