求正则表达式
要求:首位、末位不能是-,只允许有大写英文字母,数字,-。位数不能小于6位。

解决方案 »

  1.   

    暈死
    多做几层判断     if (str.Length > 6 && !str.EndsWith("-")) 
                {
                    if (Regex.IsMatch(str, "[^-][A-Z,-]"))
                    {
                        Console.Write("符合要求");
                    }                
                }
    不以什麽結束我也判斷不來哦
      

  2.   

    http://download.csdn.net/source/2024655
    书名:C#入门经典(第3版) ISBN:9787302127352[十位:7302127352] 作者:(美)Karli Watson Christian Nagel 出版社:清华大学出版社 出版日期:2006年05月 页数:864
      

  3.   

    http://myweb.cn.yahoo.com/tagurl.html?p=%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F了解完这个网页,相信你就不会再有任何正则表达式的问题了。这个地方提供书写的正则表达式的验证。
      

  4.   

    ^[a-zA-Z0-9][a-zA-Z0-9-]{4,}[a-zA-Z0-9]$
      

  5.   

     string[] str = new string[] { "123456","-12","12-","12-22A","a-A-A-1","aa--aa","1234569","-"};            Regex re = new Regex(@"^(?!-)[A-Z0-9-]{5,}[A-Z0-9]$");
                foreach (string s in str)
                {
                    Console.WriteLine(re.Match(s).Value);
                }
      

  6.   

    using System;
    using System.Text.RegularExpressions;
    namespace Test
    {
    class Program
    {
    public static void Main(string[] args)
    {
    string str = "-98978";
    if(Regex.IsMatch(str,@"^[^-]\w{4}[^-]$"))
    {
    Console.WriteLine("格式正确");
    }
    Console.ReadKey(true);
    }
    }
    }
      

  7.   


    ^(?!-)[A-Z0-9]{5,}((?!-)[A-Z0-9])$
      

  8.   

    Regex re = new Regex("[A-Z0-9][A-Z0-9-]{4,}[A-Z0-9]", RegexOptions.None);
    MatchCollection mc = re.Matches("text");
    foreach (Match ma in mc)
    {
    }
      

  9.   


    ^[A-Z0-9][A-Z0-9\-]{4,}[A-Z0-9]$看来是来晚了