Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google应用程序脚本中的正则表达式_Javascript_Regex_Google Apps Script - Fatal编程技术网

Javascript Google应用程序脚本中的正则表达式

Javascript Google应用程序脚本中的正则表达式,javascript,regex,google-apps-script,Javascript,Regex,Google Apps Script,我在正则表达式方面遇到了问题,它在RegExr.com和JS控制台上运行良好。但在谷歌应用程序脚本上失败 regex.gs function parse() { var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/ var html = get_html(); Logger.log(html.match(regExp)); } 函数解析() { var regExp=/mobilehe

我在正则表达式方面遇到了问题,它在RegExr.com和JS控制台上运行良好。但在谷歌应用程序脚本上失败

regex.gs

function parse()
{
  var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/

  var html = get_html();  
  Logger.log(html.match(regExp));

}
函数解析()
{
var regExp=/mobileheading=\“End\sDate\”\>[^\您需要设置标志。因此,以下代码应该可以工作:

function parse() {
    var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/g;
    var html = get_html();
    Logger.log(html.match(regExp));
}
函数解析(){

var regExp=/mobileheading=\“End\sDate\”\>[^\您的正则表达式看起来不错。请记住向正则表达式添加“g”标志以捕获所有匹配项。get\u html()方法本身可能有问题

function parse() {
  var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/g
  var html = HtmlService.createHtmlOutputFromFile("page.html").getContent();
  Logger.log(html.match(regExp));  
}
函数解析(){

var regExp=/mobileheading=\“End\sDate\”\>[^\n谢谢你,阿米特!你说得对,问题出在
get\u html()
上。我觉得正则表达式不起作用。但是从html文件读取输出是一个很好的技巧!