Created
November 14, 2012 09:58
-
-
Save kevinblake/4071293 to your computer and use it in GitHub Desktop.
Parse YouTube Id from Url
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
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