Created
September 19, 2014 15:56
-
-
Save h1k3r/f67d1d0a9643b0a42f07 to your computer and use it in GitHub Desktop.
Js function to extract urls from text (with silly regexp)
This file contains 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
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