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

正则表达式(mtracer)解决办法

2012-02-26 
正则表达式(mtracer)divahref http://www.baidu.com title baidu www.baidu.com /a/divahre

正则表达式(mtracer)
<div>
<a   href= "http://www.baidu.com "   title= 'baidu '> www.baidu.com </a>
</div>
<a   href= "http://www.sina.com.cn "   title= 'sina '> www.sina.com.cn </a>

我需要取的数据如下:
是div之间的。
http://www.baidu.com
baidu
www.baidu.com

[解决办法]
using System.Text.RegularExpressions;

string str = " <div> <a href=\ "http://www.baidu.com\ " title= 'baidu '> www.baidu.com </a> </div> ";

string link = Regex.Match(str, "href=\ "([^]]+)\ " title ").ToString();
link = Regex.Replace(link, "(href=\ ")|(\ " title) ", " ");

string title = Regex.Match(str, "title= '([^]]+) '> ").ToString();
title = Regex.Replace(title, "(title= ')|( '> ) ", " ");

string size = Regex.Match(str, " '> ([^]]+) </a> ").ToString();
size = Regex.Replace(size, "( '> )|( </a> ) ", " ");


//验证通过~~~

热点排行