日期:2014-05-17  浏览次数:20395 次

.net正则表达式匹配,求助
这是信息:
<tr><td height=27 align=center>现货铂金</td><td height=18 align=center>289.26</td><td height=18 align=center class=fontok>-1.04</td><td height=18 align=center>-0.36%</td><td height=18 align=center>290.61</td><td height=18 align=center>288.86</td></tr><tr><td height=27 align=center>现货钯金</td><td height=18 align=center>117.83</td><td height=18 align=center class=fontok>-0.55</td><td height=18 align=center>-0.46%</td><td height=18 align=center>118.48</td><td height=18 align=center>117.57</td></tr><tr><td height=27 align=center>现货白银</td><td height=18 align=center>5482</td><td height=18 align=center class=fontok>-21</td><td height=18 align=center>-0.38%</td><td height=18 align=center>5524</td><td height=18 align=center>5470</td></tr>


我想获取<tr><td height=27 align=center>现货铂金</td><td height=18 align=center>289.26</td><td height=18 align=center>-0.36%</td><tr>这样的数据,怎么做啊?

我自己写的正则表达式,只能获取这一行,还显示两次。

哪位大牛帮忙解决下啊,不胜感激

------解决方案--------------------
C# code

  string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
                string pattern = @"(?i)(<tr[^>]*?>(<td[^>]*?>[^<]*?</td>){2})((?!</tr>).)*?(<td[^>]*?>[^<]*?%[^<]*?</td>).*?(</tr>)";
                string[] tempStr_list = Regex.Matches(tempStr, pattern).Cast<Match>().Select(a=>Regex.Replace(a.Value,pattern,"$1$4$5")).ToArray();
                /*
                         [0]    "<tr><td height=27 align=center>现货铂金</td><td height=18 align=center>289.26</td><td height=18 align=center>-0.36%</td></tr>"    string
                        [1]    "<tr><td height=27 align=center>现货钯金</td><td height=18 align=center>117.83</td><td height=18 align=center>-0.46%</td></tr>"    string
                        [2]    "<tr><td height=27 align=center>现货白银</td><td height=18 align=center>5482</td><td height=18 align=center>-0.38%</td></tr>"    string

                 */