求证则表达式一个

rottenapple 2009-09-21 01:24:10
<td class="y_tabledata1" nowrap align="right">AAAA</td><td class="y_tabledata1" align="right">4,703.40</td><td class="y_tabledata1" align="right">4,703.60</td><td class="y_tabledata1" align="right">4,662.20</td><td class="y_tabledata1" align="right">4,693.70</td><td class="y_tabledata1" align="right">2,265,912,800</td><td class="y_tabledata1" align="right">4,693.70</td>

想把上面这段html 标签里的值取出来,比如AAAA,4703.40,....怎么做啊?可以用一个group吧?
谢谢
...全文
85 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wackyboy 2009-09-21
  • 打赏
  • 举报
回复

"(?i)(?<=<td[^<>]*>)[^<>]+"
Match m = Regex.Match(input, "(?i)(?<=<td[^<>]*>)[^<>]+");
Console.WriteLine(m.Value);
rottenapple 2009-09-21
  • 打赏
  • 举报
回复
thanks 0210, it works
mbh0210 2009-09-21
  • 打赏
  • 举报
回复

<td[^>]*>(?<info>[\s|\S]*?)(?=</td>)


取info就可以
rottenapple 2009-09-21
  • 打赏
  • 举报
回复
ls的方法好像可以,可是我测试的时候只是输出了最后一个值,为什么呢?用你的测试代码题却没问题,两者的差别就在于源字符串",""的不同,应该没啥影响吧,是转译?
十八道胡同 2009-09-21
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Regex re = new Regex(@"((?i)<td[^>]*>(?<num>.*?)</td>)+");
string str = @"<td class=""y_tabledata1"" nowrap align=""right"">AAAA </td> <td class=""y_tabledata1"" align=""right"">4,703.40 </td> <td class=""y_tabledata1"" align=""right"">4,703.60 </td> <td class=""y_tabledata1"" align=""right"">4,662.20 </td> <td class=""y_tabledata1"" align=""right"">4,693.70 </td> <td class=""y_tabledata1"" align=""right"">2,265,912,800 </td> <td class=""y_tabledata1"" align=""right"">4,693.70 </td> ";
MatchCollection mc = re.Matches(str);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups["num"].Value);
}

}
}
}

AAAA
4,703.40
4,703.60
4,662.20
4,693.70
2,265,912,800
4,693.70
Press any key to continue . . .
wxg22526451 2009-09-21
  • 打赏
  • 举报
回复
Regex re = new Regex(@" (?is)<td\s+(?:(?!</td>).)+>(.*?)</td>", RegexOptions.None);
MatchCollection mc = re.Matches(@"<td class=""y_tabledata1"" nowrap align=""right"">AAAA </td> <td class=""y_tabledata1"" align=""right"">4,703.40 </td> <td class=""y_tabledata1"" align=""right"">4,703.60 </td> <td class=""y_tabledata1"" align=""right"">4,662.20 </td> <td class=""y_tabledata1"" align=""right"">4,693.70 </td> <td class=""y_tabledata1"" align=""right"">2,265,912,800 </td> <td class=""y_tabledata1"" align=""right"">4,693.70 </td>");
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups[1].Value);
}
wxg22526451 2009-09-21
  • 打赏
  • 举报
回复
(?is)<td[^<]*>(.*?)</td>
wuyq11 2009-09-21
  • 打赏
  • 举报
回复
Regex re = new Regex(@"<td[^>]+>(.*?)</td>",RegexOptions.IgnoreCase|RegexOptions.Singleline);
Match m = re.Match(s);
if (m.Success)
{
Console.WriteLine(m.Groups[1].Value);
}

111,092

社区成员

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

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

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