请教一个正则表达式问题,万分感谢

chinls_chow 2008-08-26 11:20:26
小弟刚参加工作不久,接到个任务是要取人民币汇率的数据,可是正则用的不熟实在没办法解决了,我只能写这个 <font.*?(color=#575757>)(? <1>[^ <]+)分到第一个分组,后面怎么写试了半天也写不对,请有相关知识的朋友指导一下,也欢迎有自己想法的朋友留下你的思路,大家一起学习共勉,不胜感激!

下面是要取的网页的源代码,要取各国的钱和后面汇率的数据,如取美元/人民币,6.8522等等.

\r\n </script>\r\n </body>\r\n </html>\r\n\t\t\t <table height=\"100\" cellSpacing=\"0\" cellPadding=\"0\" width=\"335\" align=\"center\" border=\"0\">\r\n\t\t\t\t <tr>\r\n\t\t\t\t\t <td width=\"194\" height=\"69\"> <A href=\"RmbOTC.aspx\"> <IMG src=\"img/btn_rmbotc2.gif\" border=\"0\" alt=\"人民币外汇即期行情\"> </A> </td>\r\n\t\t\t\t\t <td width=\"141\" height=\"69\"> <A href=\"RmbMidPrice.aspx\"> <IMG src=\"img/btn_rmbmid1.gif\" border=\"0\" alt=\"人民币汇率中间价\"> </A> </td>\r\n\t\t\t\t </tr>\r\n\t\t\t\t <tr>\r\n\t\t\t\t\t <td vAlign=\"top\" align=\"center\" width=\"335\" colSpan=\"2\" height=\"31\"> <IMG src=\"img/btn_rmbotc3.gif\" border=\"0\" alt=\"人民币外汇即期询价行情\"> </td>\r\n\t\t\t\t </tr>\r\n\t\t\t </table>\r\n\t\t\t <table style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#ffffff\" cellSpacing=\"0\" cellPadding=\"0\"\r\n\t\t\t\twidth=\"750\" align=\"center\" border=\"1\">\r\n\t\t\t\t <tr>\r\n\t\t\t\t\t <td vAlign=\"top\"> <table cellspacing=\"0\" rules=\"all\" bordercolor=\"White\" border=\"1\" id=\"DataGrid1\" height=\"180\" width=\"100%\">\r\n\t <tr class=\"Ptblue\" align=\"center\" bgcolor=\"#DCE7ED\">\r\n\t\t <td> <font size=\"2\">货币 </font> </td> <td> <font size=\"2\">买价 </font> </td> <td> <font size=\"2\">卖价 </font> </td> <td> <font size=\"2\">最高 </font> </td> <td> <font size=\"2\">最低 </font> </td> <td> <font size=\"2\">涨跌 </font> </td> <td> <font size=\"2\">涨跌幅% </font> </td> <td> <font size=\"2\">昨收 </font> </td> <td> <font size=\"2\">更新时间 </font> </td>\r\n\t </tr> <tr class=\"Ptgray\" align=\"center\" bgcolor=\"#F0F4F8\">\r\n\t\t <td> <font size=\"2\"> <font color=#575757>美元/人民币 </font> </font> </td> <td> <font size=\"2\">6.8511 </font> </td> <td> <font size=\"2\">6.8522 </font> </td> <td> <font size=\"2\">6.8557 </font> </td> <td> <font size=\"2\">6.8448 </font> </td> <td> <font size=\"2\"> <font color=red>0.0016 </font> </font> </td> <td> <font size=\"2\">0.02 </font> </td> <td> <font size=\"2\">6.8501 </font> </td> <td> <font size=\"2\">08/26 17:33 </font> </td>\r\n\t </tr> <tr class=\"Ptgray\" align=\"center\" bgcolor=\"#DCE7ED\">\r\n\t\t <td> <font size=\"2\"> <font color=#575757>港币/人民币 </font> </font> </td> <td> <font size=\"2\">0.87737 </font> </td> <td> <font size=\"2\">0.87760 </font> </td> <td> <font size=\"2\">0.87802 </font> </td> <td> <font size=\"2\">0.87657 </font> </td> <td> <font size=\"2\"> <font color=red>0.00037 </font> </font> </td> <td> <font size=\"2\">0.04 </font> </td> <td> <font size=\"2\">0.87712 </font> </td> <td> <font size=\"2\">08/26 17:33 </font> </td>\r\n\t </tr> <tr class=\"Ptgray\" align=\"center\" bgcolor=\"#F0F4F8\">\r\n\t\t <td> <font size=\"2\"> <font color=#575757>100日元/人民币 </font> </font> </td> <td> <font size=\"2\">6.2425 </font> </td> <td> <font size=\"2\">6.2446 </font> </td> <td> <font size=\"2\">6.2615 </font> </td> <td> <font size=\"2\">6.2369 </font> </td> <td> <font size=\"2\"> <font color=red>0.0123 </font> </font> </td> <td> <font size=\"2\">0.2 </font> </td> <td> <font size=\"2\">6.2313 </font> </td> <td> <font size=\"2\">08/26 17:33 </font> </td>\r\n\t </tr> <tr class=\"Ptgray\" align=\"center\" bgcolor=\"#DCE7ED\">\r\n\t\t <td> <font size=\"2\"> <font color=#575757>欧元/人民币 </font> </font> </td> <td> <font size=\"2\">10.0045 </font> </td> <td> <font size=\"2\">10.0070 </font> </td> <td> <font size=\"2\">10.0791 </font> </td> <td> <font size=\"2\">10.0058 </font> </td> <td> <font size=\"2\"> <font color=green>-0.0949 </font> </font> </td> <td> <font size=\"2\">-0.94 </font> </td> <td> <font size=\"2\">10.1006 </font> </td> <td> <font size=\"2\">08/26 17:33 </font> </td>\r\n\t </tr> <tr class=\"Ptgray\" align=\"center\" bgcolor=\"#F0F4F8\">\r\n\t\t <td> <font size=\"2\"> <font color=#575757>英镑/人民币 </font> </font> </td> <td> <font size=\"2\">12.5750 </font> </td> <td> <font size=\"2\">12.5793 </font> </td> <td> <font size=\"2\">12.6490 </font> </td> <td> <font size=\"2\">12.5771 </font> </td> <td> <font size=\"2\"> <font color=green>-0.0821 </font> </font> </td> <td> <font size=\"2\">-0.65 </font> </td> <td> <font size=\"2\">12.6592 </font> </td> <td> <font size=\"2\">08/26
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
浮生若梦丶 2008-08-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 baihe_591 的回复:]
Regex.Matches(textBox2.Text, @"(? <currency>[\u4e00-\u9fa5]+/人民币).*?>(? <rate>[^\s <]+)");

不知道正确不正确.
[/Quote]
太花啦,看不了
baihe_591 2008-08-27
  • 打赏
  • 举报
回复
Regex.Matches(textBox2.Text, @"(?<currency>[\u4e00-\u9fa5]+/人民币).*?>(?<rate>[^\s<]+)");

不知道正确不正确.
格拉 2008-08-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 HimeTale 的回复:]
C# code textBox3.Clear();
MatchCollection mc = Regex.Matches(textBox2.Text, @"(?<currency>[\u4e00-\u9fa5]+/[\u4e00-\u9fa5]+).*?>(?<rate>[^\s<]+)");
foreach (Match m in mc)
{
textBox3.AppendText(m.Groups["currency"].Value + ":" + m.Groups["rate"].Value + Environment.NewLine);
}


输出:
美元/人民币:6.8511
港币/人…
[/Quote]学习
liuyun1987 2008-08-27
  • 打赏
  • 举报
回复
汗..HTML也不整理一下..看了眼花..
wocow2316 2008-08-27
  • 打赏
  • 举报
回复
up
HimeTale 2008-08-26
  • 打赏
  • 举报
回复
            textBox3.Clear();
MatchCollection mc = Regex.Matches(textBox2.Text, @"(?<currency>[\u4e00-\u9fa5]+/[\u4e00-\u9fa5]+).*?>(?<rate>[^\s<]+)");
foreach (Match m in mc)
{
textBox3.AppendText(m.Groups["currency"].Value + ":" + m.Groups["rate"].Value + Environment.NewLine);
}

输出:
美元/人民币:6.8511
港币/人民币:0.87737
日元/人民币:6.2425
欧元/人民币:10.0045
英镑/人民币:12.5750

效率不高...但是能用.

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧