正则表达式问题

accpbl0330 2016-01-29 11:48:27
我想用正则 Match函数 匹配2个字符串 但在判断 mc.Success 是否成功时 返回为false , 不知道哪里匹配不对。 代码如下

 
string rowData ="<a id=\"gridview1_ctl02_hyperlink1\" href=\"yushou_info.aspx?ysbh=2016-013\" style=\"display:inline-block;color: maroon\"><u>2016-013</u></a>";
rowData +=" </font></td><td bgcolor=\"white\">AAAAAAA</td><td bgcolor=\"white\">BBBBBBB</td><td bgcolor=\"white\">CCCCCC</td><td bgcolor=\"white\" width=\"10%\">2016-01-28</td></tr>";

string match= "(?s)[^>]*<a id=\"[^>]*\" href=\"[^>]*\"> style=\"[^>]*\"><u>(?<bah>.*?)</u></a>\r\n[^>]*</font></td>[^>]*<td bgcolor=\"white\">(?<lpmc>.*?)[^>]*</td>[^>]*<td bgcolor=\"white\">(?<lh>.*?)[^>]*</td>[^>]*<td bgcolor=\"white\">(?<jzmj>.*?)[^>]*</td>[^>]*<td bgcolor=\"white\" width=\"10%\">(?<ts>.*?)[^>]*</td>[^>]*</tr>"

GroupCollection matchValues = GetDomInnerHtml(rowData ,match);

public GroupCollection GetDomInnerHtml(string html, string match)
{
Regex reg = new Regex(match, RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match mc = reg.Match(html);
if (mc.Success)
return mc.Groups;
else return null;
}
...全文
142 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
accpbl0330 2016-01-29
  • 打赏
  • 举报
回复
我就是想获取rowData  里所有 td 节点中的 值
秋的红果实 2016-01-29
  • 打赏
  • 举报
回复
你的正则好长啊,首先说说要匹配哪2个字符串
accpbl0330 2016-01-29
  • 打赏
  • 举报
回复
解决了 是自己粗心 <a id=\"[^>]*\" href=\"[^>]*\"> 这里href后面多打了一个"> " 符号。
accpbl0330 2016-01-29
  • 打赏
  • 举报
回复
引用 4 楼 qq_24481075 的回复:
[quote=引用 3 楼 qq_24481075的回复:][quote=引用 2 楼 accpbl0330的回复:]我就是想获取rowData  里所有 td 节点中的 值
<td.+?>(.+)</td> 这个试试看,我手机写的没测试……[/quote] 额写错了错了加号改成*[/quote] <a>节点 和 <u>节点都不用管了? 测试过还是false
蓝光999 2016-01-29
  • 打赏
  • 举报
回复
引用 3 楼 qq_24481075的回复:
[quote=引用 2 楼 accpbl0330的回复:]我就是想获取rowData  里所有 td 节点中的 值
<td.+?>(.+)</td> 这个试试看,我手机写的没测试……[/quote] 额写错了错了加号改成*
蓝光999 2016-01-29
  • 打赏
  • 举报
回复
引用 2 楼 accpbl0330的回复:
我就是想获取rowData  里所有 td 节点中的 值
<td.+?>(.+)</td> 这个试试看,我手机写的没测试……

111,129

社区成员

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

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

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