只允许通过下面语句:select cno,name,sex from table; 其中只允许cno,name,sex;不允许其他字符出现如 cno,...name,..sex
cno,name,。。sex 

解决方案 »

  1.   

    那除了select cno,name,sex from table,还会有什么允许出现的字符串
      

  2.   

    select  cno,name,sex from table就是cno,name,sex之间除了“,”通过,不允许在cno,name,sex之间出现cno,name,...sex多余的符号,多余的符号是和...
      

  3.   

    就是匹配能通过select  cno,name,sex from table
    如果是select cno,name,...sex from table不能通过
      

  4.   

    直接用这个进行匹配不就可以了?select cno,name,sex from table 
      

  5.   


    public static void main(String[] args) throws Exception {
    //the sql you want to volidate
    String str = "select cno,name,sex from table;";
    boolean isCorrect = SqlValidate_Select(str);
    } public static boolean SqlValidate_Select(String str) {
    String pattern = "^select\\s+?(?:\\w+?,)*?\\w+?\\s+?from.+?;$";
    Pattern patt = Pattern.compile(pattern);
    Matcher matcher = patt.matcher(str);
    if (matcher.matches()) {
    return true;
    } else {
    return false;
    }
    }
      

  6.   

    Regex reg = new Regex(@"^\w{11}$");
     Match m = reg.Match("cno,name,sex"); 
      {
          MessageBox.Show("匹配上了");
       }
      

  7.   

    Regex reg = new Regex(@"^\w{11}$"); 
     Match m = reg.Match("cno,name,sex");  
    if (m.Success==true)
      { 
          MessageBox.Show("匹配上了"); 
       }