问题描述
这样的正则怎么写啊!怎么才能获取到下面的湖南地图湖南电视湖南电视台<TR><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%D8%CD%BC">湖南地图</A></TD><TD>624 <SPANclass=up>↑ +11%</SPAN></TD><TD>0 <SPANclass=dn>↓ -100%</SPAN></TD><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%D8%CD%BC">查看</A></TD><TD> </TD></TR><TR><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3">湖南电视</A></TD><TD>181 <SPANclass=dn>↓ -25%</SPAN></TD><TD>6 <SPANclass=dn>↓ -54%</SPAN></TD><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3">查看</A></TD><TD> </TD></TR><TR><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3%CC%A8">湖南电视台</A></TD><TD>896 <SPANclass=dn>↓ -8%</SPAN></TD><TD>6 <SPANclass=dn>↓ -54%</SPAN></TD><TD><Ahref="http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3%CC%A8">查看</A></TD><TD> </TD></TR>
解决方案
解决方案二:
没看明白什么意思
解决方案三:
正在看正则,学习~~~帮顶,期待高手
解决方案四:
usingSystem;usingSystem.Text.RegularExpressions;publicclassTest{staticvoidMain(){stringstrHtml=@"<TR><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%D8%CD%BC"">湖南地图</A></TD><TD>624 <SPANclass=up>↑ +11%</SPAN></TD><TD>0 <SPANclass=dn>↓ -100%</SPAN></TD><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%D8%CD%BC"">查看</A></TD><TD> </TD></TR><TR><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3"">湖南电视</A></TD><TD>181 <SPANclass=dn>↓ -25%</SPAN></TD><TD>6 <SPANclass=dn>↓ -54%</SPAN></TD><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3"">查看</A></TD><TD> </TD></TR><TR><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3%CC%A8"">湖南电视台</A></TD><TD>896 <SPANclass=dn>↓ -8%</SPAN></TD><TD>6 <SPANclass=dn>↓ -54%</SPAN></TD><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%E7%CA%D3%CC%A8"">查看</A></TD><TD> </TD></TR>";MatchCollectionmc=Regex.Matches(strHtml,@"<TR>[sS]*?href="".*?>(.*?)</",RegexOptions.IgnoreCase);for(inti=0;i<mc.Count;i++){Console.WriteLine(mc[i].Groups[1].Value);}//湖南地图//湖南电视//湖南电视台Console.ReadKey();}}
解决方案五:
引用3楼hackztx的回复:
C#codeusingSystem;usingSystem.Text.RegularExpressions;publicclassTest{staticvoidMain(){stringstrHtml=@"<TR><TD><Ahref=""http://index.baidu.com/main/word.php?word=%BA%FE%C4%CF%B5%D8%CD%BC"">湖南地图</A></TD><TD>624 <SPANclass=up>↑ +11%</SPAN></TD><TD>0 <SPANclass=dn>↓ -100%</SPAN></TD><…
强人正解
解决方案六:
shref=""http://index.baidu.com/main/word.php?word=[^>]+>([^<]+)</a>
解决方案七:
<TR>[sS]*?<TD>s*?<A[^>]*?>(.+?)</A>
取group[1]
解决方案八:
Regexreg=newRegex(@"(?<=<TR>).*?<A[^>]*>([^/]+)?(?=</A>)",RegexOptions.IgnoreCase|RegexOptions.Singleline);MatchCollectionmc=reg.Matches("htmlStr");foreach(Matchminmc){s+=m.Groups[1].Value+",";}
s="湖南地图,湖南电视,湖南电视台,";
解决方案九:
该回复于2008-05-09 11:14:24被版主删除