Skip to content

Instantly share code, notes, and snippets.

@vlrmprjct
Created September 22, 2014 16:03
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 vlrmprjct/2c26803f7c05e3716499 to your computer and use it in GitHub Desktop.
Save vlrmprjct/2c26803f7c05e3716499 to your computer and use it in GitHub Desktop.
findurl's in string
function findUrls( text )
{
var source = (text || '').toString();
var urlArray = [];
var url;
var matchArray;
// Regular expression to find FTP, HTTP(S) and email URLs.
var regexToken = /(((ftp|https?):\/\/)[\-\w@:%_\+.~#?,&\/\/=]+)|((mailto:)?[_.\w-]+@([\w][\w\-]+\.)+[a-zA-Z]{2,3})/g;
// Iterate through any URLs in the text.
while( (matchArray = regexToken.exec( source )) !== null )
{
var token = matchArray[0];
urlArray.push( token );
}
return urlArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment