Method findText with regexp
google-apps-script, google-docs, google-docs-api
Solution
You have to pass a string to this function, but it will convert it into RegExp for you. This is not like the `string.match` function that differentiates strings from regexes.
`doc.findText("any\\s+regex.*works");`
Problem
I want to find a string in the google document using findText(searchPattern) method. My searchPattern is regexp as in following: ``` var doc = DocumentApp.getActiveDocument().getBody(); var textToHighlight = ''; textToHighlight = new RegExp( "this" ); textLocation = doc.findText(textToHighlight); ``` But it gave me the following error instead search the text: Google Apps Script: Argument cannot be null: prompt I read the documentation of the findText method in Text class. Here it specifies the searchPattern as string. Is there any alternative to find the text using regexp. Thanks