[英]Regex - how to exclude this kind of sql from all sql statements in java?
how to exclude this kind of sql from all sql statements: alter table ... column ...
如何从所有sql语句中排除这种sql: alter table ... column ...
I wrote a regex but it doesn't work in java: alter\\s+table\\s+.*(?<!\\s+column\\s+.*)
我写了一个正则表达式,但是在Java中不起作用: alter\\s+table\\s+.*(?<!\\s+column\\s+.*)
I don't see why you need a lookaround, just use this pattern: 我不明白为什么需要环顾四周,只需使用以下模式即可:
alter\s+table\s+.*\bcolumn\b.*
Code snippet: 程式码片段:
String sql = "ALTER TABLE table_name DROP COLUMN column_name;";
if (sql.matches("(?i:alter\\s+table\\s+.*\\bcolumn\\b.*)")) {
System.out.println("not allowed");
}
else {
System.out.println("allowed");
}
By Simply Replacing all the keywords with '' or ' ' 只需将所有关键字替换为“或”即可
Code : 代码:
String sql = "ALTER TABLE table_name DROP COLUMN column_name";
sql.replace("alter").('');
sql.replace("column").(' ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.