C#正则表达式去除XML标签

案例1:

//数据源

String strSource = "xxx100 11 100";

 

//表达式

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

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

String replacementpattern = @"$2";

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

//输出结果:

//xxx100 11 100

案例2:

//标签中带属性

String strSource = "xxx100 11 100";

//表达式

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

 

转载于:https://www.cnblogs.com/Harvard-L/p/5051803.html

你可能感兴趣的:(C#正则表达式去除XML标签)