Last active
May 7, 2023 04:07
-
-
Save marnovo/6a0dfb51979f7fefab0ff0ee3764512c to your computer and use it in GitHub Desktop.
Extract URLs from HTML source, as website or email.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This only outputs the first found URL, not all of them. Any idea how to output more?