首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

两个简略的正则获取

2012-12-16 
两个简单的正则获取pstronga hrefhttp://www.xxx.com某某公司/a/strong/p如何用正则代码获

两个简单的正则获取
<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 快速解决立马结贴


我试试看

热点排行