帮忙写一个正则表达式 只允许通过下面语句: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("匹配上了"); } jdk源码中问题 WebService的原理和过程是怎样的? WizardPage的finish置灰 创建一个网站需要学那些技术? 循环打印空心菱形,三个循环。 新手来了,来捧捧场。 aix jdk安装问题,急!!! if分支语句可以不用{}吗? JAVA违例的小问题 jb5 datastore 的serial number 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("匹配上了");
}