strign str = "safsf[@id]fsf[@title]fsdf";
有这么一串字符串 我要取出[@id],[@title]
请问怎么实现....

解决方案 »

  1.   

      对  我要把[@id] , [@title] 保存在数组里去
      

  2.   

    try...string str = "safsf[@id]fsf[@title]fsdf";
    Regex reg = new Regex(@"\[@[^\[\]]*\]");
    MatchCollection mc = reg.Matches(str);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Value + "\n";
    }
      

  3.   

    using System;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        string str = "safsf[@id]fsf[@title]fsdf"; 
        Regex r1 = new Regex(@".*?(\[.*?\])");
        Regex r2 = new Regex(@"(.*,).*");    string[] t = r2.Replace(r1.Replace(str, "$1,"), "$1").Trim(',').Split(',');
        // 这个字符串数组 t 就是你要的!    foreach (string s in t)
          Console.WriteLine(s);
      }
    }