Reputation: 2653
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
Upvotes: 4
Views: 2091
Reputation: 17752
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");
Upvotes: 4