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