我有一段文字
[:+ This is a message +:] text here ... [:+ This is another message +:] ..... text [:+ This message allows + , : , ]character +:]我希望将其中的
This is a message
This is another message
This message allows + , : , ]character 
一句正则提取出来, 请问哪位大虾能搞定啊? 谢谢

解决方案 »

  1.   

    so easy...string test = "[:+ This is a message +:] text here ... [:+ This is another message +:] ..... text [:+ This message allows + , : , ]character +:] ";
     MatchCollection mc = Regex.Matches(test, @"(?<=\[:\+\s*)[\s\S]*?(?=\s*\+:\])");
     foreach (Match m in mc)
     {
         richTextBox2.Text += m.Value + "\n";
     }
    /*输出
     This is a message 
     This is another message 
     This message allows + , : , ]character 
    */
      

  2.   

    \[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*\[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*[^a-z]*([a-z\s]+[^\]]*\][a-z]*)\b代码这样:
    Regex reg=new Regex(@"\[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*\[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*[^a-z]*([a-z\s]+[^\]]*\][a-z]*)\b");
    string result=string.Empty;
    Match m=reg.Matche(yourText);
    if(m.Success)
    {
         result+=m.Groups[1].Value+"\r\n"+m.Groups[2].Value+"\r\n"+m.Groups[3].Value;  
    }
      

  3.   


    //将错就错,不循环,一次输出结果。修正上面的正则。
    (?is)\[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*\[[^a-z]*([a-z\s]+)[^\]]*\][^\[]*[^a-z]*([a-z\s]+[^\]]*\][a-z]*)\b