Skip to content

Instantly share code, notes, and snippets.

View leandrocustodio's full-sized avatar

Leandro Custodio leandrocustodio

  • TheoremOne
  • Brazil
View GitHub Profile
@leandrocustodio
leandrocustodio / gist:5139185
Last active December 14, 2015 19:49 — forked from Godoy/gist:5032291
Expressão regular em C# para pegar ID de vídeos de uma url do Youtube.
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;
}