Question: I am trying to write a script using Google Scripts to edit one of my Google Docs. I am trying to replace the text in
I am trying to write a script using Google Scripts to edit one of my Google Docs. I am trying to replace the text in between two parentheses.
Ex:
Before: Hello my name is "Laura", and I am a student.
After script: Hello my name is , and I am a student.
Google Apps say that it does not accept regex (?) based on what I found below on Google App's site:
replaceText(searchPattern, replacement)
Replaces all occurrences of a given text pattern with a given replacement string, using regular expressions.
The search pattern is passed as a string, not a JavaScript regular expression object. Because of this you'll need to escape any backslashes in the pattern.
This methods uses Google's RE2 regular expression library, which limits the supported syntax.
The provided regular expression pattern is independently matched against each text block contained in the current element.
- - - - - - - -
this is my code so far:
function myFunction() { var doc = DocumentApp.getActiveDocument(); var body = doc.getBody().getText(); body.editAsText().replaceText(/ *\"[^)]*\" */g, ""); return body; }
but it does not work.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
