日期:2014-05-18 浏览次数:20802 次
<Run Tag="/qqqq/qqqqq" xml:space="preserve"> </Run> <Run Tag="end" xml:space="preserve"> </Run> <Run Tag="/aaa/aaa" xml:space="preserve"> </Run> <Run Tag="end" xml:space="preserve"> </Run>
<Canvas Tag="/qqqq/qqqqq" Width="0"/> <Canvas Tag="end" Width="0"/> <Canvas Tag="/aaa/aaa" Width="0"/> <Canvas Tag="end" Width="0"/>
string str=@"<Run Tag=""/qqqq/qqqqq"" xml:space=""preserve""> </Run> <Run Tag=""end"" xml:space=""preserve""> </Run> <Run Tag=""/aaa/aaa"" xml:space=""preserve""> </Run> <Run Tag=""end"" xml:space=""preserve""> </Run> <Run Tag="""" xml:space=""preserve""> </Run>"; string result = Regex.Replace(str, @"(?i)<Run\s+(Tag=""[^""]+"")[^>]*?>\s*</Run>", "<Canvas $1 Width=\"0\"/>"); Console.WriteLine(result); /* <Canvas Tag="/qqqq/qqqqq" Width="0"/> <Canvas Tag="end" Width="0"/> <Canvas Tag="/aaa/aaa" Width="0"/> <Canvas Tag="end" Width="0"/> <Run Tag="" xml:space="preserve"> </Run> */