Skip to content

Instantly share code, notes, and snippets.

@kevinblake
Created November 14, 2012 09:58
Show Gist options
  • Save kevinblake/4071293 to your computer and use it in GitHub Desktop.
Save kevinblake/4071293 to your computer and use it in GitHub Desktop.
Parse YouTube Id from Url
public static class YouTubeUrl
{
private const string UrlRegex = @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)";
public static string GetVideoId(string videoUrl)
{
var regex = new Regex(UrlRegex);
var match = regex.Match(videoUrl);
if (match.Success)
{
return match.Groups[1].Value;
}
return videoUrl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment