本文實例講述了C#提取網(wǎng)頁中超鏈接link和text部分的方法。分享給大家供大家參考,具體如下:
string s = "..";Regex re = new Regex(@"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^/s>]*))[^>]*>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);Match m = re.Match(s);if(m.Success){ string link = m.Groups["href"].Value; string text = Regex.Replace(m.Groups["text"].Value,"<[^>]*>",""); Console.WriteLine("link:{0}/ntext:{1}", link, text);}更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#正則表達式用法總結(jié)》及《C#字符串操作技巧總結(jié)》
希望本文所述對大家C#程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選