It is easy to search and replace text in Google Documents with the DocumentApp service of Google Apps Script. You can use use findText method with simple regular expressions to find text elements in the document that match a pattern and replace them with the specified text. All well and good but in some cases, this simple search and replace function may fail if the search text does not transform into a valid regular expression.
Some more regex goodness this time from Amit Agarwal who provides some very useful tips on escaping characters when using the
DocumentApp service and
findText method. Click through to the source link for more details.
Source: How to Find and Replace Text in Google Docs with RegEx Search Patterns – Digital Inspiration
Member of Google Developers Experts Program for Google Workspace (Google Apps Script) and interested in supporting Google Workspace Devs.