标签:
案例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>";
标签:
原文地址:http://www.cnblogs.com/Harvard-L/p/5051803.html