using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|playlist\?|watch\?v=|watch\?.+(?:&|&);v=))([a-zA-Z0-9\-_]{11})?(?:(?:\?|&|&)index=((?:\d){1,3}))?(?:(?:\?|&|&)?list=([a-zA-Z\-_0-9]{34}))?(?:\S+)?";
string input = @"https://www.youtube.com/playlist?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=4UcfECYbDYQ&index=1&list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://youtu.be/4UcfECYbDYQ?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=Svmor6ouuO4&index=4&list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=M44e92KoIaE
https://youtu.be/M44e92KoIaE
https://www.youtube.com/embed/videoseries?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx