I'm working on processing a URL in to it's constituent parts from my stand alone script on Google App Script.
My issue is that the regex buiding tools on the net tell me that my regex is right, but I get only one value.
Specifically, my code is:
function UrlComponents(url) {
const _urlMatchPattern = /^((http[s]?):\/)?\/?([^:\/\s]+)(:([^\/]*))?((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?$/mig; // Source: http://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex
if (!_urlMatchPattern.test(url))
return new Array();
var urlMatches = url.match(_urlMatchPattern);
if (urlMatches != null)
{
Logger.log("Count:" + Math.floor(urlMatches.length));
for (var i=0; i<Math.floor(urlMatches.length);i++)
Logger.log("Position " + i + ": " + urlMatches[i]);
}
return urlMatches;
}
When I test this by running the code, the output is a single array element containing the fill string. However, the same thing through a regex testing tool (e.g. http://gskinner.com/RegExr/ or www.regexplanet.com/advanced/java/) gives the correct information.
Any help / advice / well mannered pointing out of my inevitable stupid error is gratefully welcomed.
With thanks, Jonny