Created
September 22, 2014 16:03
-
-
Save vlrmprjct/2c26803f7c05e3716499 to your computer and use it in GitHub Desktop.
findurl's in string
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
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