日期:2014-05-19  浏览次数:20796 次

是不是匹配错了?(c#)
string   headerRegex   =   "(? <=manu_elems\ "> )[^ <]{1,} ";

string   textRegex   =   "(? <= '100 '   height= '50 '> )[^/ ";

以上是正则表达式

<div   class= "manu_elems "> <div   class= "manu_elem ">
<div   class= "manu_photo ">
<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 "> </a> </div>
<div   class= "manu_name "> <a   href= "http://detail.zol.com.cn/mp4_player_index/subcate272_1081_list_1.html "   title= "纽曼   MP4播放器 "   class= 'a_hei12 '> 纽曼 </a> </div>
</div>
<div   class= "manu_elem ">
<div   class= "manu_photo ">
<a   href= "http://detail.zol.com.cn/mp4_player_index/subcate272_1670_list_1.html "> <img   src= 'http://img2.zol.com.cn/manu_photo/1670_.jpg '   alt= "歌美   MP4播放器 "   width= '100 '   height= '50 '   border= "0 "> </a> </div>
<div   class= "manu_name "> <a   href= "http://detail.zol.com.cn/mp4_player_index/subcate272_1670_list_1.html "   title= "歌美   MP4播放器 "   class= 'a_hei12 '> 歌美 </a> </div>
</div>
<div   class= "manu_elem ">
<div   class= "manu_photo ">
<a   href= "http://detail.zol.com.cn/mp4_player_index/subcate272_133_list_1.html "> <img   src= 'http://img2.zol.com.cn/manu_photo/133_.jpg '   alt= "MSI(微星)   MP4播放器 "   width= '100 '   height= '50 '   border= "0 "> </a> </div>
<div   class= "manu_name "> <a   href= "http://detail.zol.com.cn/mp4_player_index/subcate272_133_list_1.html "   title= "MSI(微星)   MP4播放器 "   class= 'a_hei12 '> MSI(微星) </a> </div>
</div>

------解决方案--------------------
string headerRegex = "(? <=manu_elems\ "> )[^ <]{1,} ";

代码中只有 <div class= "manu_elems "> <div class= "manu_elem "> 这里出现了manu_elems "> ,而其后紧跟着“ <”,你的正则要求匹配一个或多个非“ <”字符,当然匹配不到

string textRegex = "(? <= '100 ' height= '50 '> )[^/ ";

这里“[”没有闭合,正则本身就是错的,说下你可得到什么结果吧,给你看下正则