0

正規表現を使用して文字列を検索しようとしています。例:これは私のサンプル文字列です

  **if (c == 0) {
                count = 0;
                du.insert(ipAddress, c);
            } else {
                count = c;
            }
            getDate();
            String query1 = "select * from loginmaster where  username = '" + username + "' and password = '" + password + "' ;";
            //out.println(query1);
            //out.println(request.getParameter("Group1"));
            session.setAttribute("group", request.getParameter("Group1"));
            if (count < 3) {
                if (request.getParameter("Group1").equals("With")) {
                    LoginQuery q = new LoginQuery();
                    checked = q.Checker(query1);
                    if (checked == false) {
                        connection.getConnection();
                        connection.getDML("insert into attack values('"+ipAddress+"','"+date+"','Attack Detected')");
                    }
                }**

正規表現を使用して、この文字列でクエリを見つけようとしています

String regExp = "\b(ALTER|CREATE|DELETE|DROP|EXEC(UTE){0,1}|INSERT( +INTO){0,1}|MERGE|SELECT|UPDATE|UNION( +ALL){0,1})\b";

String regExp = "(;|\\s)(exec|execute|select|insert|update|delete|create|alter|drop|rename|truncate|backup|restore)\\s";

しかし、私は出力もエラーも得ていません。

残りのコードは次のとおりです。

    Pattern p = Pattern.compile(regExp, Pattern.CASE_INSENSITIVE);                
                while ((line = reader.readLine()) != null) {
                    Matcher m = p.matcher(line);
                    if (m.matches()) {
                        JOptionPane.showMessageDialog(this, "innnnnnnnnnn");
                        System.err.println(m.group(1));
                    }
}

助けてください

4

1 に答える 1

0

大文字と小文字が一致しないため、正規表現は入力文字列と一致しません。

正規表現は大文字で記述されていますが、入力文字列には小文字の一致が含まれています。したがって、正規表現で大文字と小文字を区別しないようにするか、小文字変換してください。

ところで、あなたの正規表現はクエリinsert into attack ...とメソッドを分離できませんでした:du.insert(ipAddress, c);

于 2012-08-06T11:04:52.233 に答える