string strCommand="create proc test as select *from t1"
 
 if (!Regex.IsMatch(strCommand, "create proc"))
   {}
 if (!Regex.IsMatch(strCommand, "create procedure"))
   {}
 if (!Regex.IsMatch(strCommand, "Create procedure"))
   {}如果strCommand存在create proc,create procedure,drop proc,drop procedure,
等只要是这样的词组.注意不区分大小写!类似下面的都不可以执行
Create Proc
Create Procedure
cReate ProcEdure
等等!

解决方案 »

  1.   

    try...if (!Regex.IsMatch(yourStr, @"(create|drop)\s+proc(edure)?\b", RegexOptions.IgnoreCase))
        richTextBox2.Text = "符合要求";
    else
        richTextBox2.Text = "不符合要求";
      

  2.   

    if (!Regex.IsMatch(strCommand, "(?i)(create|drop) proc(dure)?"))
       {}
      

  3.   


                string str = "drop proc sfsfdsf";
                Console.WriteLine(Regex.IsMatch(str, @"(create|drop)\s+proc(edure)?", RegexOptions.IgnoreCase));
      

  4.   

    @"(?i)\b(create|drop)\s+proc(edure)?\b", 
      

  5.   


    string strCommand = "create proc test as select *from t1";
    Regex reg = new Regex(@"create proc|create procedure|drop proc|drop procedure", RegexOptions.IgnoreCase);
    if (reg.Match(strCommand).Success) return;
      

  6.   

    private static void Main(string[] args)
            {
                string sql = "drops procedure test as select *from t1";
                Console.WriteLine(IsSqlOk(sql));
                Console.ReadLine();
            }        public static bool IsSqlOk(string sql)
            {
                Regex regex =
                    new Regex("(create proc)|(create procedure)|(drop proc)|(drop procedure)", RegexOptions.IgnoreCase);
                return regex.IsMatch(sql);
            }