写了半天了,总是不行...
下班之前要搞定,急哇..第一个:
<a class="underline" href="http://www.test.com">
<h2>标题</h2>
</a>第二个:
<a href="http://www.test.com" class="offerHeading" target="_blank">
标题
</a>第三个:
<a href="http://www.test.cp,"
onclick="show()" title="test" class="company_name">
标题
</a>主要是写三个正则表达式,获取出以上三个链接中的 href属性和 标题..
求高人帮忙哇...
下班之前要搞定,急哇..第一个:
<a class="underline" href="http://www.test.com">
<h2>标题</h2>
</a>第二个:
<a href="http://www.test.com" class="offerHeading" target="_blank">
标题
</a>第三个:
<a href="http://www.test.cp,"
onclick="show()" title="test" class="company_name">
标题
</a>主要是写三个正则表达式,获取出以上三个链接中的 href属性和 标题..
求高人帮忙哇...
解决方案 »
- 寻找灵感,想做QQ空间那样的上传图片之后在修改
- 大虾指点迷津:未将对象引用设置到对象的实例?
- 允许window.open问题
- 关于checkbox取值的老问题,我弄了两天加一个通宵就是搞不定,大家帮帮忙,来看看
- 什么水平就可以研究PETSHOP4.0了
- IIS中怎么配置无限多个虚拟目录?
- Session为何老师丢失?
- 请问各位高手,怎样在程序里控制TableCell在TableRow里的显示格式
- 点击linkbutton后,如何在page_load时获得该linkbutton的UniqueID?
- 那位大哥有.net framworks sdk ,给小弟传一下!qq:53662315
- Asp.net实现iis启动/停止?
- Gridview执行一个事件,可以绑定两次吗?
<h2>标题 </h2>
</a> ";
MatchCollection mc = Regex.Matches(yourstr, @"(?is)<a\s+[^>]*href=""(?<url>[^""]*)"">\s*<h2>(?<title>.*)</h2>", RegexOptions.None);
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups["url"].Value);
Console.WriteLine(ma.Groups["title"].Value);
}
/*
http://www.test.com
标题
*/
标题
</a> ";
MatchCollection mc = Regex.Matches(yourstr, @"(?is)<a\s+[^>]*href=""(?<url>[^""]*)""[^>]*>\s*(?<title>.*)</a>", RegexOptions.None);
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups["url"].Value);
Console.WriteLine(ma.Groups["title"].Value);
}
/*
http://www.test.com
标题
*/
string strPattern=@"a[\s]+href=(?<Link>[^\s>]+)[^>]*>(?<Text>[^<]*)</a>";
MatchCollection Matches=Regex.Matches(webDocContent,strPattern,RegexOptions.IgnoreCase|RegexOptions.Compiled);
foreach(Match NextMatch in Matches)
{
string URL=NextMatch.Groups["Link"].Value.ToString().Trim();
string URLText=NextMatch.Groups["Text"].Value.ToString().Trim();
Response.Write(URL);
Response.Write(URLText);
}
(?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*>\s*(?<title>[^<]*)\s*</a>
第二个和第三个不能写成通用的哦,
第二个必须考虑 class="offerHeading"
第三个必须考虑 class="company_name"
第二个和第三个不能写成通用的哦,
第二个必须考虑 class="offerHeading"
第三个必须考虑 class="company_name"
(?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*>\s*<h2>(?<title>[^<]*)</h2>\s*</a>
//2
(?is)<a\s+[^>]*href="(?<url>[^"]*)"\s*class="offerHeading"[^>]*>\s*(?<title>[^<]*)\s*</a>
//3
(?is)<a\s+[^>]*href="(?<url>[^"]*)"[^>]*class="company_name"[^>]*>\s*(?<title>[^<]*)\s*</a>