Skip to content

Instantly share code, notes, and snippets.

@liamcurry
Created August 16, 2012 19:23
Show Gist options
  • Save liamcurry/3372873 to your computer and use it in GitHub Desktop.
Save liamcurry/3372873 to your computer and use it in GitHub Desktop.
Nice JS Snippets
// 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>');
// 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