Extract Id from Twitch Clip URL

Multi tool use
Extract Id from Twitch Clip URL
How can I extract the Id of a Twitch Clip URL.
Example:
https://clips.twitch.tv/KindYummyCarrotPeteZaroll?some=1
I need only the Id part, for example: https://clips.twitch.tv/[ID]?v=1
https://clips.twitch.tv/[ID]?v=1
The Id in the top example is KindYummyCarrotPeteZaroll
. Any query string if comes after should be ignored and not be part of the Id.
KindYummyCarrotPeteZaroll
I tried:
MatchCollection matches = Regex.Matches(url, @"^(https://clips.twitch.tv/)(?:(?!http).)*?");
But I wasn't able to capture the Id in a group. I am using ASP.NET and C#.
(?<=twitch.tv/)(w*)(?=?)
1 Answer
1
No need for Regex:
string str = "https://clips.twitch.tv/KindYummyCarrotPeteZaroll?some=1";
string id = str.Split('/', '?')[3];
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try
(?<=twitch.tv/)(w*)(?=?)
– pkpkpk
Jun 30 at 7:10