C# Question

Delete a value with between two values

Can be a little complicated, but I tried very hard and get the result. I'm getting the video links from a site with HtmlAgilityPack.

HtmlWeb hw = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = hw.Load(@"C:\Users\e9396\Desktop\r.html");
foreach (HtmlNode links in doc.DocumentNode.SelectNodes("//a[@href]"))
{
if (links.NextSibling != null)
{
ArrayList ArrayLinksList = new ArrayList();
ArrayLinksList.Add(links.Attributes["href"].Value);
listbox.Items.AddRange(ArrayLinksList.ToArray());
}
}


But some of the links are as follows.

/video/93409905175
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93409905175&st.cmd=userMain
/video/93361801751
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93361801751&st.cmd=userMain
/video/93442476567
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93442476567&st.cmd=userMain
/video/93409839639
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93409839639&st.cmd=userMain
/video/93442411031
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93442411031&st.cmd=userMain
/video/93442345495
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93442345495&st.cmd=userMain
/video/93461940759
/dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93461940759&st.cmd=userMain


links like this "/video/93409905175" OK.

But i want to delete links like this


"/video/93409905175 /dk?cmd=VideoVitrinaPopup&st.redirect=myVideo&st.vvp_cmd=VideoVitrinaPopupMovieEdit&st.vv_movieId=93409905175&st.cmd=userMain".


I can't erase it because of the ID in bold the marked locations.

I want to be like that, thanks.

/video/93409905175
/video/93361801751
/video/93442476567
/video/93409839639
/video/93442411031
/video/93442345495
/video/93461940759

Answer

Thanks for progress Travis Sharp, but the type of the value returned by the procedure FilterLinks the links are probably not suitable.

public static IEnumerable<string> FilterLinks(HtmlAgilityPack.HtmlDocument doc, string regexFilter)
{
    var regex = new Regex(regexFilter);
    return doc.DocumentNode
              .SelectNodes("//a[@href]")
              .Where(n => n.NextSibling != null 
                       && regex.IsMatch(n.GetAttributeValue("href", string.Empty)))
              .Select(n => n.GetAttributeValue("href", string.Empty));
}

FilterLinks we get the returned value from a variable.
And we call it like this:

var xLinkeler = FilterLinks(doc, @"^\/video\/[0-9]*");
foreach (var iett in xLinkeler)
{
    listbox.Items.Add(iett);
}