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,""); } }
|
|