感觉是xml啊,如果用regex处理就比较乱,容易出错,代码不好维护啊。用xml处理吧。
code:
stirng old=....;
XmlDocument doc =new XmlDocument();
doc.LoadXml(old);
//find all parent of node RoleId
//xpath: //RoleID/parent::*
XmlNode nodes()=doc.SelectNodes(@"//RoleID/parent::*");
XmlNode parent;
XmlNode self;
foreach(parent in nodes)
{
   //find node what will be replaced
   //xpath: ./RoleID
   self=parent.SelectSingleNode(@"./RoleID);
   if(self != null) parent.Remove(self);
}string newString=doc.OuterXml;

解决方案 »

  1.   

    c#不熟,有语法错误,大约是这样。
    正则表达式为:
    pattern=@"<RoleID.+RoleID>"
    replaceStatement=""
      

  2.   

    if the string is in xml format, it is better to use Xml classes so you can keep the integrity of the string, otherwise, tryusing System.Text.RegularExpressions;string OldString 
    ="<UserInfo><Error></Error><UserID><Value></Value><Error></Error></UserID><UserName><Value></Value><Error></Error></UserName><UserPwd><Value></Value><Error></Error></UserPwd><RoleID><Value></Value><Error></Error></RoleID></UserInfo>";NewString = Regex.Replace(OldString ,@"<RoleID>.*?</RoleID>", "", RegexOptions.IgnoreCase | RegexOptions.Singleline);
      

  3.   

    这是属于自构造、自解析的类xml的自定义字符串
    有了saucer(思归) 的回复,我已经知道该如何处理了,谢谢saucer(思归) 。