日期:2014-05-17  浏览次数:20431 次

两个简单的正则获取
<p><strong><a href="http://www.xxx.com">某某公司</a></strong></p>

如何用正则代码
获取href连接[http://www.xxx.com]
获取a标签文本[某某公司] 

语言.NET 快速解决立马结贴
------最佳解决方案--------------------
            string input = @"<p><strong><a href=""http://www.xxx.com"">某某公司</a></strong></p>";
            Regex regex = new Regex(@"<a\s+href=""(?<href>[^""]+)"">(?<value>[^<]+)</a>");
            MatchCollection collection = regex.Matches(input);
            foreach (Match item in collection)
            {
                Console.WriteLine("href={0}     value={1}", item.Groups["href"].Value, item.Groups["value"].Value);
            }
------其他解决方案--------------------

             string input = @"<p><strong><a href=""http://www.xxx.com"">某某公司</a></strong></p>";
             var first = Regex.Matches(input, @"<a.*?href=[""']([^""']+)[^>]+>([^<]+)</a>").Cast<Match>().Select(t => new { href = t.Groups[1].Value, txt = t.Groups[2].Value }).ToArray();
------其他解决方案--------------------
引用:
<p><strong><a href="http://www.xxx.com">某某公司</a></strong></p>

如何用正则代码
获取href连接[http://www.xxx.com]
获取a标签文本[某某公司] 

语言.NET 快速解决立马结贴


我试试看