帮忙写一个正则表达式 只允许通过下面语句:select cno,name,sex from table; 其中只允许cno,name,sex;不允许其他字符出现如 cno,...name,..sexcno,name,。。sex 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那除了select cno,name,sex from table,还会有什么允许出现的字符串 select cno,name,sex from table就是cno,name,sex之间除了“,”通过,不允许在cno,name,sex之间出现cno,name,...sex多余的符号,多余的符号是和... 就是匹配能通过select cno,name,sex from table如果是select cno,name,...sex from table不能通过 直接用这个进行匹配不就可以了?select cno,name,sex from table 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; } } Regex reg = new Regex(@"^\w{11}$"); Match m = reg.Match("cno,name,sex"); { MessageBox.Show("匹配上了"); } Regex reg = new Regex(@"^\w{11}$"); Match m = reg.Match("cno,name,sex"); if (m.Success==true) { MessageBox.Show("匹配上了"); } 菜鸟弱弱的问一下:为什么java-version运行不了…… 求租一个scjp的问题 菜鸟送分求助!(50分) Thread的问题 有哪些控件是可以setBounds的? 求助 使用jbuilder database pilot连接sybase数据库出现的问题 安装Oracle的问题!!!!!!!!!!!!!!!!!!!!!!! java中有没有这样的控件 如何去掉IE里面对刷新post结果页面的提示框? Method.invoke调用问题??? jsp+tomcat+mysql+servlet+javabean配置问题 如果求得多个矩形的相交后的非闭合区域。
如果是select cno,name,...sex from table不能通过
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;
}
}
Match m = reg.Match("cno,name,sex");
{
MessageBox.Show("匹配上了");
}
Match m = reg.Match("cno,name,sex");
if (m.Success==true)
{
MessageBox.Show("匹配上了");
}