会正则的进来解决问题

zetee 2010-03-08 03:18:28
<TD width=30>3</TD>
<TD>60.217.232.199</TD>
<TD width=60>80</TD>
<TD width=60>CN</TD></TR>


这段html 中

我只要
3
60.217.232.199
80
CN
怎么用正则取出来

...全文
58 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fcluser 2010-03-08
  • 打赏
  • 举报
回复
string strHtml = " <TD width=30>3 </TD> <TD>60.217.232.199 </TD> <TD width=60>80 </TD> <TD width=60>CN </TD> </TR>";
//string pattern=@"\<td>\s*(?:<[^>]+>)?\s*([^<]+)\s*(?:<[^>]+>)?\s*</td>";
string pattern = "<td([^<]+)?>([^<]+)</td>";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
if (regex.IsMatch(strHtml))
{
MatchCollection matchs = regex.Matches(strHtml);
foreach (Match match in matchs)
{
Console.WriteLine(match.Groups[2].Value);
}
qlzf11140820 2010-03-08
  • 打赏
  • 举报
回复
string sHTML = @"<TD width=30>3 </TD> 
<TD>60.217.232.199 </TD> <TD width=60>80 </TD>
<TD width=60>CN </TD> </TR>";
string str = System.Text.RegularExpressions.Regex.Replace(sHTML, "<[^>]+>", "");
cpp2017 2010-03-08
  • 打赏
  • 举报
回复

string sHTML = @"<TD width=30>3 </TD>
<TD>60.217.232.199 </TD> <TD width=60>80 </TD>
<TD width=60>CN </TD> </TR>

";

Regex reg = new Regex("<td[^>]*?>([^>]*?)</td>", RegexOptions.IgnoreCase);
MatchCollection mc = reg.Matches(sHTML);
foreach (Match m in mc)
{
Response.Write(m.Result("$1") + "<BR>");
}

111,092

社区成员

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

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

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