string regstr = @"(?i)(?<=<td.*?.*?>)[^<]+(?=</td>)"; //提取td的文字           
string regstr = @"<a\s+href=(?<url>.+?)>(?<content>.+?)</a>"; //提取链接的内容
string regstr = @"<td.+?><a\s+href=(?<url>.+?)>(?<content>.+?)</a></td>"; //提取TD中链接的内容
string regstr = @"<td.+?><span.+?>(?<content>.+?)</span></td>"; //提取TD中span的内容
string regstr = @"<td.+?>(?<content>.+?)</td>"; //获取TD之间所有的内容
string regstr = @"<td>(?<content>.+?)-<font color=#0000ff>推荐</font></td>"; //获取内容

正则替换:

一循环内替换:

            string regstr = @"(?i)[\<]td.*?[\>].*?(</td>)"; //提取页面所有TD内容
string regReplace = @"(?i)[\<]td.*?[\>]"; //将所有<td......> 替换成<td>

Regex reg
= new Regex(regstr, RegexOptions.IgnoreCase | RegexOptions.Singleline);
MatchCollection mc
= reg.Matches(data);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups[
0].ToString());
Console.WriteLine(
"------------------------------");
string s = Regex.Replace(m.Groups[0].ToString(), regReplace, "<td>", RegexOptions.IgnoreCase);
Console.WriteLine(s);

}

二统一替换

                 string regstr = @"(?i)[\<]td.*?[\>].*?(</td>)"; //提取页面所有TD内容
string regReplace = @"(?i)[\<]td.*?[\>]"; //将所有<td......> 替换成<td>

Regex reg
= new Regex(regstr, RegexOptions.IgnoreCase | RegexOptions.Singleline);
string s = Regex.Replace(data, regReplace, "<td>", RegexOptions.IgnoreCase);
MatchCollection mc
= reg.Matches(s);
foreach (Match m in mc)
{

Console.WriteLine(m.Groups[
0].ToString());
Console.WriteLine(
"------------------------------");


}

  

  

相关文章:

  • 2022-12-23
  • 2021-10-26
  • 2022-02-25
  • 2022-01-22
  • 2022-12-23
  • 2022-01-18
  • 2021-11-20
  • 2021-07-23
猜你喜欢
  • 2022-01-22
  • 2021-11-22
  • 2021-09-30
  • 2021-09-21
  • 2021-10-18
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案