如我有正则表达式
<{this\.\S+?}>([\S\s]*?)<{/this\.\S+?}>
检索内容为
-------------------
<{this.header}>
我是头
<{/this.header}> 
<{this.main}>
我是主要内容
<{/this.main}> 
<{this.footer}>
我是尾
<{/this.header}> 
-------------------
现在是可以的,但是不够严谨

<{this.header}><{/this.foot}>
也是过得了的那应该如何写最好呢?谢谢

解决方案 »

  1.   

    <{this\.\S+?}>([\S\s]*?)<{/this\.\S+?}>-----------------------------
    <{this\.\S+?}>([\S\s]+?)<{/this\.\S+?}>
      

  2.   


    @"<{(this\.[^}]+)}>[^<>]*<{/\1}>"
      

  3.   

    @"<{(this\.[^}]+)}>[^<>]*<{/\1}>"
    --------
    楼上这么测试不过
    ??!!
      

  4.   

    <{this.header}>
    我是头
    <{/this.header}> 
    <{this.main}>
    我是主要内容
    <{/this.main}> 
    <{this.footer}>
    我是尾
    <{/this.header}> 
    -----------------最后一个应该是<{/this.footer}>
      

  5.   

    try...            Regex reg = new Regex(@"(?is)<\{this\.([^{}]+)\}>(.*?)<\{/this\.\1}>");
                MatchCollection mc = reg.Matches(yourStr);
                foreach(Match m in mc)
                {
                    richTextBox2.Text += m.Value + "\n-------------\n";
                }
      

  6.   

    {需要转义吗?keke 是不是少了\  在最后的}之前
      

  7.   

      string str = @"<{this.header}>
    我是头
    <{/this.header}> 
    <{this.main}>
    我是主要内容
    <{/this.main}> 
    <{this.footer}>
    我是尾
    <{/this.footer}> 
    <{this.header}><{/this.foot}>
    ";
                Regex re = new Regex(@"<{([^}]+)}>([^<]*?)<{/\1}>");
                MatchCollection mc = re.Matches(str);
                foreach(Match m in mc)
                    Console.WriteLine(m.Value);这个是可以的
      

  8.   

    客客 ,你在{}之前加\  是为了转义吗?我没加也是对的 string str = @"<{this.header}>
    我是头
    <{/this.header}> 
    <{this.main}>
    我是主要内容
    <{/this.main}> 
    <{this.footer}>
    我是尾
    <{/this.footer}> 
    <{this.header}><{/this.foot}>
    ";
                Regex re = new Regex(@"(?is)<{this\.([^{}]+)}>(.*?)<{/this\.\1}>");            MatchCollection mc = re.Matches(str);
                foreach(Match m in mc)
                    Console.WriteLine(m.Value);
      

  9.   


    不用Group的答案全部都可以踢飞掉^_^!