Created
August 16, 2012 19:23
-
-
Save liamcurry/3372873 to your computer and use it in GitHub Desktop.
Nice JS Snippets
This file contains hidden or 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
// Converts #hashtags, @usernames, and http://regularlin.ks | |
var tweet = 'Final day for the 2 @nvidia *INSTANT ACCESS* @PlanetSide2 #BetaKeys. RT: https://t.co/gKpxu1eY and/or Follow: http://t.co/3ryWGeEz to enter!'; | |
tweet = tweet | |
.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a target=_blank href="$1">$1</a>') | |
.replace(/(^|\s)@(\w+)/g, '$1<a target=_blank href=//twitter.com/$2>@$2</a>') | |
.replace(/(^|\s)#(\w+)/g, '$1<a target=_blank href=//twitter.com/search?q=%23$2>#$2</a>'); | |
This file contains hidden or 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
// http://stackoverflow.com/a/9102270/105428 | |
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; | |
var match = url.match(regExp); | |
if (match && match[2].length === 11) { | |
return match[2]; | |
} else { | |
//error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment