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

高分,求正则表达式,该如何处理

2012-01-30 
高分,求正则表达式各位大虾:帮忙呀.想从以下HTML中,提取012280000998唯舞独尊(激情活跃版)...蔡依林3.0057

高分,求正则表达式
各位大虾:帮忙呀.

想从以下HTML中,提取

012280000998
唯舞独尊(激情活跃版)...
蔡依林
3.00
572

  <TR     >  
                                            <TD   width= "90 "   height=18>  
                                                <div   align= "center "> <a   href= "javascript:void(0) "   onclick= "window.open( 'flashring_info.jsp?rt_id=012280000998 ', '_blank ', 'status=no,toolbar=no,menubar=no,scrollbars=no,location=no,width=389,height=220,resizable=no ') "   title= "点击查看铃音信息 "   class= "ringlink "> 012280000998 </a> </div> </TD>
                                            <TD   width= "5 "> </TD>
                                            <TD> <a   href= "javascript:void(0) "   onclick= "window.open( 'flashring_info.jsp?rt_id=012280000998 ', '_blank ', 'status=no,toolbar=no,menubar=no,scrollbars=no,location=no,width=389,height=220,resizable=no ') "   title= "点击查看铃音信息 "   class= "ringlink "> 唯舞独尊(激情活跃版)... </a> </TD>
                                            <TD   width= "5 "> </TD>
                                            <TD   width= "110 "> 蔡依林 </TD>
                                            <TD   width= "5 "> </TD>
                                            <TD   width= "45 "> 3.00 </TD>
                                            <TD   width= "50 "> 572 </TD>
                                            <TD   width= "38 "> <div   align= "center "> <a   href= "javascript:void(0) "   onclick= "window.open( 'elisten.jsp?rt_id=012280000998 ', 'trylisten ', 'status=no,toolbar=no,menubar=no,scrollbars=no,location=no,width=215,height=220,resizable=no ') "   title= "点击试听铃音 "   class= "ringlink "> <img   name= "fr_r17_c20 "   src= "images/icon01.gif "   width= "14 "   height= "14 "   border= "0 "   alt= " "> </a> </div> </TD>
                                            <TD   width= "38 "> <div   align= "center "> <a   href= "javascript:void(0) "   onclick= "window.open( 'ebuy.jsp?rt_id=012280000998 ', '_blank ', 'status=no,toolbar=no,menubar=no,scrollbars=no,location=no,width=390,height=235,resizable=no ') "   title= "点击购买 "   class= "ringlink "> <img   name= "fr_r17_c20 "   src= "images/icon02.gif "   width= "11 "   height= "14 "   border= "0 "   alt= " "> </a> </div> </TD>


                                        </TR>



[解决办法]
只是一个思路,匹配 "> "和 " < "之间的内容,应该就能得到你要的.....
\> [\w]*[\W]*\ <,自己试试
[解决办法]
"> "和 " < "之间不包括 " < "的内容....(看起来好象不是很合理....)
[解决办法]
up,应该简单
[解决办法]
试下,看看这样是不是更简洁,通用性更好一些

string yourStr = .................;
MatchCollection mc = Regex.Matches(yourStr, @ "> (?! <)([^> ]*?)(( </a> </div> )| </a> )? </td> ",RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox1.Text += m.Groups[1].Value+ "\n "; //提取结果
}
[解决办法]
string yourStr = ......;
MatchCollection mc = Regex.Matches(yourStr, " <tr.+?> \\s* <td.+?> \\s+ <div.+?> \\s* <a.+?> (.+?) </a> \\s* </div> \\s* </td> \\s* <td.+?> \\s* </td> \\s* <td> \\s* <a.+?> (.+?) </a> \\s* </td> \\s* <td.+?> \\s* </td> \\s* <td.+?> (.+?) </td> \\s* <td.+?> \\s* </td> \\s* <td.+?> (.+?) </td> \\s* <td.+?> (.+?) </td> \\s* <td.+?> \\s* <div.+?> \\s* <a.+?> \\s* <img.+?> \\s* </a> \\s* </div> \\s* </td> \\s* <td.+?> \\s* <div.+?> \\s* <a.+?> \\s* <img.+?> \\s* </a> \\s* </div> \\s* </td> \\s* </tr> ", RegexOptions.IgnoreCase);
foreach(Match m in mc)
{
m.Groups[1].Vlaue;//012280000998
m.Groups[2].Vlaue;//唯舞独尊(激情活跃版)...
m.Groups[3].Vlaue;//蔡依林
m.Groups[4].Vlaue;//3.00
m.Groups[5].Vlaue;//572
}

热点排行