<strong oid="1585760687" style="display:none"><a href="javascript:void(0);" onclick="App.miniblogDel('3347491776905084',null,this)"><strong lang="CX0043">删除</strong></a><span class="MIB_line_l">|</span></strong><!-- 转发 -->
<a href="javascript:void(0);" onclick="GB_SUDA._S_uaTrack('weibo_transmit','origin_transmit');return false;" action-type="forward" action-data="fid=xjVtDsYkk&uid=1585760687&mid=3347491776905084&name=%E7%BA%A2%E8%9C%BB%E8%9C%93888_r1i&rootuid=&rootmid=&rootname=&allowforward=1&allowComment=1&allowRootComment=0"><strong lang="CD0023">转发</strong><strong id="num_3347491776905084" rid="3347491776905084" type="rttCount"></strong></a>
<!-- 转发 -->
<span class="MIB_line_l">|</span>
<a href="javascript:void(0);" onclick="App.addfavorite_miniblog('3347491776905084');"><strong lang="CL1003">收藏</strong></a>
<!-- 评论 -->
<span class="MIB_line_l">|</span>
<a id="_comment_count_miniblog2_3347491776905084" href="javascript:void(0);" onclick="GB_SUDA._S_uaTrack('weibo_transmit','origin_comment');scope.loadCommentByRid(1585760687, 'miniblog2', '新浪微博', '3347491776905084', '', '', '', 1, 0, 1);"><strong lang="CL1004">评论</strong><strong rid="3347491776905084" type="commtCount"></strong></a>
<!-- 评论 -->
帮朋友做个小程序,遇到一个问题,从上面的结果中,需要把action-data="fid=xjVtDsYkk&uid=1585760687&mid=3347491776905084&name=%E7%BA%A2%E8%9C%BB%E8%9C%93888_r1i&rootuid=&rootmid=&rootname=&allowforward=1&allowComment=1&allowRootComment=0"给取出来。大哥们,帮帮忙,实在是不行了。立马给分。
Regex reg = new Regex(@"(?is)(?<=<a[^>]*?)action-data=(['""\s]?)[^'""\s]+\1");
foreach (Match m in reg.Matches(str))
Console.WriteLine(m.Value);
string source = @"<strong oid=""1585760687"" style=""display:none""><a href=""javascript:void(0);"" onclick=""App.miniblogDel('3347491776905084',null,this)""><strong lang=""CX0043"">删除</strong></a><span class=""MIB_line_l"">|</span></strong><!-- 转发 -->
<a href=""javascript:void(0);"" onclick=""GB_SUDA._S_uaTrack('weibo_transmit','origin_transmit');return false;"" action-type=""forward"" action-data=""fid=xjVtDsYkk&uid=1585760687&mid=3347491776905084&name=%E7%BA%A2%E8%9C%BB%E8%9C%93888_r1i&rootuid=&rootmid=&rootname=&allowforward=1&allowComment=1&allowRootComment=0""><strong lang=""CD0023"">转发</strong><strong id=""num_3347491776905084"" rid=""3347491776905084"" type=""rttCount""></strong></a>
<span class=""MIB_line_l"">|</span>
<a href=""javascript:void(0);"" onclick=""App.addfavorite_miniblog('3347491776905084');""><strong lang=""CL1003"">收藏</strong></a>
<span class=""MIB_line_l"">|</span>
<a id=""_comment_count_miniblog2_3347491776905084"" href=""javascript:void(0);"" onclick=""GB_SUDA._S_uaTrack('weibo_transmit','origin_comment');scope.loadCommentByRid(1585760687, 'miniblog2', '新浪微博', '3347491776905084', '', '', '', 1, 0, 1);""><strong lang=""CL1004"">评论</strong><strong rid=""3347491776905084"" type=""commtCount""></strong></a>"; string patten = @"(?is)<a.*(?<content>action-data=""[^""]+"")"; //\s.*
Regex reg = new Regex(patten);
MatchCollection collection = reg.Matches(source);
MessageBox.Show(collection.Count.ToString());
if (collection.Count > 0)
{
foreach (Match m in collection)
{
MessageBox.Show(m.Groups["content"].Value); }
}
else
{
MessageBox.Show("No Match");
}
if(m.Success)
str = m.Groups["data"].Value;
Match match = Regex.Match(s, @"(?<=<a[^>]+?)action-data="".*?""");
if (match.Success)
Response.Write(match.Value);