本帖最后由 zhouxicai 于 2013-07-03 14:22:07 编辑

解决方案 »

  1.   

    是这样?string str = "hello [index]student, welcome to [index]regex world!";
                    var result = Regex.Matches(str, @"(?i)(?<=\[index\])[^\[\]]+").OfType<Match>().Select(a => a.Value).ToList();
                    /*
      [0] "student, welcome to " string
    [1] "regex world!" string
                     */
      

  2.   

    Quote: 引用 2 楼 Return_false 的回复:

    是这样?
    是像读取红色区域,字符长度不定的![index]student,[index]regex
      

  3.   

     string str = "hello [index]student, welcome to [index]regex world!";
                    var result = Regex.Matches(str, @"(?i)(?<=\[index\])[^\[\]\s,,]+").OfType<Match>().Select(a => a.Value).ToList();
                    /*
      [0] "student" string
    [1] "regex" string
                     */
      

  4.   


    可否解释下 Regex.Matches(str, @"(?i)(?<=\[index\])[^\[\]]+").OfType<Match>().Select(a => a.Value).ToList(); 这句!初学不好理解!
      

  5.   

    可否解释下!谢谢!这是Lambda扩展方法:换成一般的方法就是
    List<string> list = new List<string>();
    MatchCollection mcs = Regex.Matches(str, @"(?i)(?<=\[index\])[^\[\]\s,,]+");
    foreach(Match ma in msc)
    {
      list.Add(ma.Value)
    }