读书人

正则表达式(c#)解决方法

发布时间: 2012-01-24 23:11:54 作者: rapoo

正则表达式(c#)
<a href=\ "http://detail.zol.com.cn/mp4_player_index/subcate272_1081_list_1.html\ "> <img src= 'http://img2.zol.com.cn/manu_photo/1081_.jpg ' alt=\ "纽曼 MP4播放器\ " width= '100 ' height= '50 ' border=\ "0\ "> 纽曼abc </a>

以上是字符串:

我需要匹配以下数据:

http://detail.zol.com.cn/mp4_player_index/subcate272_1081_list_1.html

http://img2.zol.com.cn/manu_photo/1081_.jpg

纽曼abc



[解决办法]
string str= " <a href=\ "http://detail.zol.com.cn/mp4_player_index/subcate272_1081_list_1.html\ "> <img src= 'http://img2.zol.com.cn/manu_photo/1081_.jpg ' alt=\ "纽曼 MP4播放器\ " width= '100 ' height= '50 ' border=\ "0\ "> 纽曼abc </a> ";
Regex reg=new Regex( " <a href=\ "([^\ "]+?)\ "> <img src= '([^ ']+?) '[^> ]*?> ([^ <]+?) </a> ");
foreach(Match m in reg.Matches(str))
{
string a=m.Groups[1].Value;
string b=m.Groups[2].Value;
string c=m.Groups[3].Value;
}
[解决办法]
Match vMatch = Regex.Match(test,
@ " <a href= " "(.*?) " "> <img src= '(.*?) '.*?> ([^ <> ]*) </a> ");
Console.WriteLine(vMatch.Result( "$1 "));
Console.WriteLine(vMatch.Result( "$2 "));
Console.WriteLine(vMatch.Result( "$3 "));

读书人网 >C#

热点推荐