Google apps script 方法findText和regexp

Google apps script 方法findText和regexp,google-apps-script,google-docs,google-docs-api,Google Apps Script,Google Docs,Google Docs Api,我想使用findText(searchPattern)方法在google文档中查找字符串。我的搜索模式是regexp,如下所示: var doc = DocumentApp.getActiveDocument().getBody(); var textToHighlight = ''; textToHighlight = new RegExp( "this" ); textLocation = doc.findText(textToHighlight); 但它给了我以下错误

我想使用findText(searchPattern)方法在google文档中查找字符串。我的搜索模式是regexp,如下所示:

  var doc = DocumentApp.getActiveDocument().getBody();
  var textToHighlight = '';
  textToHighlight = new RegExp(  "this" ); 
  textLocation = doc.findText(textToHighlight);
但它给了我以下错误,而不是搜索文本:

Google应用程序脚本:参数不能为null:prompt

我在Text类中阅读了findText方法的文档。这里它将searchPattern指定为字符串。是否有其他方法可以使用regexp查找文本。

谢谢

您必须向该函数传递一个字符串,但它将为您将其转换为RegExp。这与区分字符串和正则表达式的
string.match
函数不同

doc.findText(“any\\s+regex.*works”)