[xxd][xxx][888]
请问怎么用C#正则把[]里的内容取出来放在数组里.
第一次用.麻烦把详细代码写一下.只写正则表达式.我怕看不懂

解决方案 »

  1.   


    public static void Display_Fuchsia()
            {
               string[] six=new string[你原来数组.Length];
                for (int count = 0; count < 你原来的数组.Length; count++)
                {
                    Regex reg = new Regex("(?<=[).*?(?=])");
                    Match ma = reg.Match(rtb.Text.ToLower());
                    while (ma.Success)
                    {
                    six[count]=你原来的数组[ma.index];
                     }            }
            }试试吧,我也是初学正则
      

  2.   

    Regex rx = new Regex(@"[(?<A>(.)*)\]", RegexOptions.Multiline);
    Regex   rx=new   Regex(@"(?<=\[)(\S*)(?=\])");   
    MatchCollection   mc   =   Regex.Matches(yourStr,   @ "\[(?<A> [^\[\]]*)\] "); 
    foreach   (Match   m   in   mc) 

          str +=   m.Groups[ "A"].Value + ","; 
    }
      

  3.   

    try...string test = "[xxd][xxx][888]";
    Regex reg = new Regex(@"(?<=\[)[^\[\]]+(?=\])");
    MatchCollection mc = reg.Matches(test);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Value + "\n";
    }
      

  4.   

    试试这个        public string[] Test(string input)
            {
                string regex = "(\\[\\w+])";
                System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) 
                            | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                return Regex.Split(input, regex, options);
            }
      

  5.   


    string test = "[xxd][xxx][888]";
    Regex reg = new Regex(@"\[(?<value>[^\]]*)\]");
    MatchCollection mc = reg.Matches(test);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups["value"].Value + "\n";
    }
      

  6.   

    谢谢.请问 <value> 是什么意思呢能把
    Regex reg=new Regex(@"\[(?<value>[^\]]*)\]");
    这个正则详细讲一下吗
      

  7.   

    value是组名,看看正则表达式语法楼主就明白了