I'm having trouble with regular expression, that works fine on RegExr.com and JS Console. But fails on Google Apps Script.
regex.gs
function parse()
{
var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/
var html = get_html();
Logger.log(html.match(regExp));
}
RegExr link - http://regexr.com/3fcsg
The link above, has the the sample text obtained from get_html().
Your regex looks good. Remember to add the "g" flag to the regex to capture all matches. It might be an issue with the get_html() method itself.
function parse() {
var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/g
var html = HtmlService.createHtmlOutputFromFile("page.html").getContent();
Logger.log(html.match(regExp));
}
You need to set the global flag. So, the following code should work :
function parse() {
var regExp = /mobileheading=\"End\sDate\"\>[^\<]+\<\/div\>/g;
var html = get_html();
Logger.log(html.match(regExp));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With