日志中的输出应为"脚本"因为这些是接下来的10个字符,后跟搜索条件"通用"。请访问www.php.net看看我的意思,你会发现搜索字符串"通用"在www.php.net上。我认为我在这段代码中犯了更多错误,对吧?
function parse() {
// parse site and store html in response
var response = UrlFetchApp.fetch('www.php.net').getContentText();
// declare search string and new regex object
var str = "/general-purpose/+10-following-charcters";
var regExp = new RegExp("/general-purpose/.{0,10}", "gi");
// find the string "general-purpose" and store the next 10 characters in response
var response = regExp.exec(str[0]);
// expected result in logger output is " scripting"
Logger.log(response);
}
答案 0 :(得分:1)
它应该是stopModal(withCode:)
而不是general-purpose(.{0,10})
。
/general-purpose/.{0,10}
也应为regExp.exec(str[0])
。
这段代码似乎工作正常
regExp.exec(str)[1]