初学c#,在论坛中,如果只引用多层引用的最外一层,怎么写正则表达式?例如
test bb

test aa
我只想引用最外面 aa 说的 test aa的留言,这个怎么写?

解决方案 »

  1.   

    trystring yourStr = ...........;
    string resultStr = Regex.Replace(yourStr, @"((?<head>\[quote\]原帖由\[i\][^\[]*?\[/i\]发表)[\s\S]*\[/quote\](?<content>[^\[\]]*?\[/quote\])|(?<head>\[quote\]原帖由\[i\][^\[]*?\[/i\]发表)[\s\S]*?(?<content>[^\[\]]*?\[/quote\]))", "${head}${content}", RegexOptions.IgnoreCase);
      

  2.   

    or try string yourStr = ...........;
    string resultStr = Regex.Replace(yourStr, @"(\[quote\]原帖由\[i\][^\[]*?\[/i\]发表)(\s*?\[quote\]原帖由\[i\][^\[]*?\[/i\]发表[\s\S]*\[/quote\])*?([^\[\]]*?\[/quote\])", "$1$3", RegexOptions.IgnoreCase);用这个吧,这个会好点
      

  3.   

    看看这个能否对你有帮助:
    http://blog.csdn.net/Eray/archive/2007/04/01/1548507.aspx