Skip to content

Instantly share code, notes, and snippets.

@marnovo
Last active May 7, 2023 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marnovo/6a0dfb51979f7fefab0ff0ee3764512c to your computer and use it in GitHub Desktop.
Save marnovo/6a0dfb51979f7fefab0ff0ee3764512c to your computer and use it in GitHub Desktop.
Extract URLs from HTML source, as website or email.
// JS from https://johnathon.blog/how-to-use-zapier-extract-all-urls-from-text/
// regex from dperini's adapted to JS & any matches https://mathiasbynens.be/demo/url-regex
var re_weburl = new RegExp(/\b((?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?)/)
output = inputData.rawBody.match(re_weburl) || [];
return output.map(function(url) {
return {url: url};
});
@Garconis
Copy link

Garconis commented May 7, 2023

This only outputs the first found URL, not all of them. Any idea how to output more?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment