Skip to content

Instantly share code, notes, and snippets.

@h1k3r
Created September 19, 2014 15:56
Show Gist options
  • Save h1k3r/f67d1d0a9643b0a42f07 to your computer and use it in GitHub Desktop.
Save h1k3r/f67d1d0a9643b0a42f07 to your computer and use it in GitHub Desktop.
Js function to extract urls from text (with silly regexp)
var detectUrls = function(text) {
var pattern = /(?:^|[\s\n\r])((?:https?:\/\/|www\.)[^\s\n\r]+)/ig,
urls = [],
matches;
while ((matches = pattern.exec(text)) !== null) {
urls.push(matches[1]);
}
return urls;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment