-
-
Save leandrocustodio/5139185 to your computer and use it in GitHub Desktop.
Expressão regular em C# para pegar ID de vídeos de uma url do Youtube.
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
string id = string.Empty; | |
if (!String.IsNullOrEmpty(@Model.Video)) | |
{ | |
System.Text.RegularExpressions.Regex regexYoutube = new System.Text.RegularExpressions.Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"); | |
System.Text.RegularExpressions.Match youtubeMatchs = regexYoutube.Match(Model.Video); | |
if (youtubeMatchs.Success) | |
{ | |
id = youtubeMatchs.Groups[1].Value; | |
} | |
} | |
string imgYoutube = "http://img.youtube.com/vi/"+id+"/1.jpg"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment