Created
September 17, 2013 18:08
-
-
Save mombrea/6598272 to your computer and use it in GitHub Desktop.
JavaScript prototype functions to parse out twitter action items into HTML
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
//Twitter Parsers | |
String.prototype.parseURL = function() { | |
return this.replace(/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&~?/.=]+/g, function(url) { | |
return url.link(url); | |
}); | |
}; | |
String.prototype.parseUsername = function() { | |
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) { | |
var username = u.replace("@","") | |
return u.link("https://twitter.com/"+username); | |
}); | |
}; | |
String.prototype.parseHashtag = function() { | |
return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) { | |
var tag = t.replace("#","%23") | |
return t.link("https://twitter.com/search?q="+tag+”&src=hash”); | |
}); | |
}; |
markni
commented
Dec 16, 2014
I think you need to escape forward slashes in parseURL
function:
// replace
/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&~?/.=]+/g
// to
/[A-Za-z]+:\/\/[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&~?/.=]+/g
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment