案例1:

//数据源

String strSource = "<Sample>xxx<Extract>100</Extract></Sample> 11 <Extract>100<Extract>";

 

//表达式

String matchpattern = @"<([^>]*)>(.*?)<\/\1>";

//$2=(.*?) 进行替换

String replacementpattern = @"$2";

//循环判断 是否还有正确的XML标签
while (Regex.IsMatch(strSource, matchpattern))
{
strSource = Regex.Replace(strSource, matchpattern, replacementpattern, RegexOptions.IgnoreCase);
}

//输出结果:

//xxx100 11 <Extract>100<Extract>

案例2:

//标签中带属性

String strSource = "<Sample Name='Sample '>xxx<Extract>100</Extract></Sample> 11 <Extract>100<Extract>";

//表达式

String matchpattern = @"<(\w+)([^>]*)>(.*?)<\/\1>";

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案