分享

正则提取数据

 alaricyyy 2015-10-29
using System.Text.RegularExpressions;
/*例1*/
Regex regtable1 = new Regex(patten1);
Match match1 = regtable1.Match(content);

 while (match1.Success )
   GroupCollection mc = match1.Groups;          
   name_s.Add(mc[1].Value);            
   match1 = match1.NextMatch();
}

/*例2*/
  string patten1 = @"(?is)</?a\b[^>]*>(?:(?!</?a).)*</a>";   //超链接过滤
// string patten1 = @"<td[^<]*>(?<xh>[^<]*)</td>";
 Regex regtable = new Regex(patten1);
 MatchCollection mc = regtable.Matches(tr);

 for (int j = 0; j < mc.Count; j=j*4)
   {
     string model2 = mc[j].Groups["xh"].Value;
    }

/*例3*/

    string patten1 = @"(?i)width[=:]\s*['""]?[^""';\s]+[""';]?";
    Regex regtable = new Regex(patten1);
    Match match1 = regtable.Match(content);

     if (match1.Success)
      {
       i++;

      MatchCollection mc = regtable.Matches(content);

     foreach (Match m in mc)
     {

      content = content.Replace(m.Value,"");
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多