Regular Expression to find the YouTube video ID from a string


Today i had to write a quick method to extract the YouTube video id from a YouTube video URL. So on with the show, lets get onto the code.

private string GetYouTubeID(string youTubeUrl)
    //Setup the RegEx Match and give it 
    Match regexMatch = Regex.Match(youTubeUrl, "^[^v]+v=(.{11}).*", 
RegexOptions.IgnoreCase); if (regexMatch.Success) { return "" + regexMatch.Groups[1].Value +
"&hl=en&fs=1"; } return youTubeUrl; }