字符串 [1]-[2]
数字内容不定.位数不定.高手帮我写个正则表达式.谢谢.

解决方案 »

  1.   

    什么目的,验证还是提取?//验证
    ^\[\d+\]-\[\d+\]$ 
    //提取
    \[\d+\]-\[\d+\]
      

  2.   

    Match match = Regex.Match(str2, @"\[\d+\]-\[\d+\]");
    程序不给执行呢?
      

  3.   

    Match match = Regex.Match(str2, @"[\d+\]-[\d+\]"); 外面加了@就不用\转义了!
      

  4.   

    Match match = Regex.Match(str2, @"\[\d+]-\[\d+]"); 
      

  5.   


    MatchCollection mc = Regex.Matches(src, @"[\d+]-[\d+]");
    foreach(Matche m in mc)
    {
     Console.WriteLine(m.value);}
    这样试试??新手也不是很懂
      

  6.   


                string testStr = @"[12]-[34]";
                Regex objRegex = new Regex(@"^\[(\d+)\]\-\[\d+\]$");
                Match objMatch = objRegex.Match(testStr);
                if (objMatch.Success) {
                    //objMatch.Groups[1].Value 这就是需要的
                }