读书人

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

发布时间: 2012-02-26 20:19:44 作者: rapoo

正则表达式(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> ) ", " ");


//验证通过~~~

读书人网 >C#

热点推荐