"[111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]" 我如何得到[]间的字符? 可以是数组 111,2222,bbbb,cccc 用.net正则如何实现,谢谢.

解决方案 »

  1.   

    int   point;   
      string   str=@"sssssssssssssssssssssss[POINT=300]内容1[/POINT]ssssssssssssss";   
      string   pattren=@"(?<=[POINT=).*?(?=].*?[/POINT])";   
      point=int.Parse(Regex.Match(str,pattren).Value);   
      Response.Write(point); 
    看这个例子
      

  2.   

    你这个得不到值吧."[111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]" 我如何得到[]间的字符? 可以是数组 111,2222,bbbb,cccc 
      

  3.   

    string pattern = "[(?<Info>.*)]}";
    MatchCollection matchCollection = Regex.Matches(str, pattern);
    foreach(Match match in matchCollection)
    {
        string matchedResult = match.Groups["Info"].Value;
    }
      

  4.   

    match.Groups["Info"].Value无值....
    str="[111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]" 
      

  5.   

    我截取过,比较笨的方法
    用string a="[111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]" ;
             a.SubString(1,3)
             第一个参数是“从第几个字符开始截取”,第二个是“截取几位”
              这样就可以截取    111   了灰常笨,呵呵
      

  6.   


    不好意思,pattern多了个},这样:string pattern = "[(? <Info>.*)]";
    MatchCollection matchCollection = Regex.Matches(str, pattern);
    foreach(Match match in matchCollection)
    {
        string matchedResult = match.Groups["Info"].Value;
      

  7.   


    //Try it.
                String str = @"[111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]";            Response.Write(String.Format("Source : {0}<br />", str));            str = str.Substring(1, str.Length - 2); 
                            Response.Write(String.Format("Temp : {0}<br />",str));            String[] arrResult = Regex.Split(str, @"\][^\[\]]+\[");            for (int i = 0; i < arrResult.Length; i++) 
                {
                    Response.Write(String.Format("{0} : {1}<br />",i,arrResult[i]));
                }            
    /*
    //Asp.net
    Source : [111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc]
    Temp : 111]asdfasdfasdf[2222]asdfasdf[bbbb]82347[cccc
    0 : 111
    1 : 2222
    2 : bbbb
    3 : cccc
    */
      

  8.   

        string str_Source = "[ssss]asdfasdfasdf[2222]asdfasdf[5555]82347[3333]"; 
        string pattern = "\\[\\w+\\]"; 
        MatchCollection matchCollection = Regex.Matches(str_Source, pattern); 
        foreach (Match match in matchCollection) { 
            MessageBox.Show(match.Value); 
        } 这种方式可以,但是出来的有 [2222] [ssss]如何出来的时候不出[]符号.
      

  9.   

    OK搞定以下为代码:{ 
        string str_Source = "[ssss]asdfas[b_b]dfasdf[2222]asdfasdf[5555]82347[3333]"; 
        string pattern = "\\[\\w+\\]"; 
        MatchCollection matchCollection = Regex.Matches(str_Source, pattern); 
        foreach (Match match in matchCollection) { 
            MessageBox.Show(match.Value.ToString().Replace("[", "").Replace("]", "")); 
        }