文章目录
在线正则校验
正则匹配sql表名称
insert into
insert into PING_TABLE (CODE, NAME) VALUES('0', '待提交'),('1', '审核中'),('2', '审核通过'),('3', '已驳回');
regex -> insert\sinto\s(\w+)\s*\(?
update
update STATE_WARNNINGSUBTYPE_TABLE set
regex -> update\s(\w+)\s*(set)?
正则表达式什么时候要加^$
public static boolean checkLength(String rule, String source) {
if (rule.contains(",")) {
String[] r = rule.split(",");
return Pattern.matches(String.format("^[0-9]{%s}(\\.[0-9]{%s})?$", (Integer.parseInt(r[0]) - Integer.parseInt(r[1])), r[1]), source);
}
if (Pattern.compile("[\\u4e00-\\u9fa5]").matcher(source).find()) {
return source.length() <= Integer.parseInt(rule);
}
return Pattern.matches(String.format("^[A-Za-z0-9]{%s}$", rule), source);
}