现在的位置: 首页 > 综合 > 正文

C# 用正则取文本中所有链接

2012年03月16日 ⁄ 综合 ⁄ 共 250字 ⁄ 字号 评论关闭

C# 用正则取文本中所有链接

 

            string pattern = @"<a\s*href=(""|')(?<href>[\s\S.]*?)(""|').*?>\s*(?<name>[\s\S.]*?)</a>";
            MatchCollection mc = Regex.Matches(srcString, pattern);
            foreach (Match m in mc)
            {
                Console.WriteLine("{0}---{1}", m.Groups["href"].Value, m.Groups["name"].Value);
            }

抱歉!评论已关闭.