案例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>";
