There is a line in a Google Doc that has a time and date stamp. I have written the following code using a regex to replace that line with the current time/date, but I am not sure why this isn't working.
function UpdateDate() {
var document = DocumentApp.getActiveDocument();
var date = new Date();
var regExp = /[0-9]{1,2}:[0-9]{2} [A-Z]{2} [A-Za-z]* [0-9]{1,2}, [0-9]{4}/;
document.replaceText(regExp, Utilities.formatDate(date, 'America/Denver', 'h:mm a MMMM dd, yyyy'));
}
If I replace the "regExp" in the document.replaceText line with, for example, "3:43 PM January 22, 2019", the code correctly replaces that with the updated date/time, but it is not able to replace the matched regex. Any ideas? Thanks!