|
@@ -4,41 +4,38 @@ import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
- * 正则表达式工具类
|
|
|
+ * 正则表达式
|
|
|
*/
|
|
|
public class RegularExpressionUtil {
|
|
|
|
|
|
//正、负整数
|
|
|
- String POSITIVE_NEGTIVE_INTEGER = "-?[1-9]\\d*";
|
|
|
+ private static final String POSITIVE_NEGTIVE_INTEGER = "-?[1-9]*$";
|
|
|
//正、负浮点数
|
|
|
- String POSITIVE_NEGTIVE_FLOAT = "-?([1-9]\\d*.\\d*|0\\.\\d*[1-9]\\d*)";
|
|
|
- //日期 yyyy MM dd
|
|
|
- String DATE_TIME = "^\\d{4}-\\d{1,2}-\\d{1,2}";
|
|
|
+ private static final String POSITIVE_NEGTIVE_FLOAT = "^-?((([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";
|
|
|
+ //日期 yyyy-MM-dd
|
|
|
+ private static final String DATE_TIME = "^[1-2][0-9][0-9][0-9]-[0-1]{0,1}[0-9]-[0-3]{0,1}[0-9]$";
|
|
|
|
|
|
public static String getRegularExpression(String filedType) {
|
|
|
- RegularExpressionUtil obj = new RegularExpressionUtil();
|
|
|
- switch (filedType) {
|
|
|
- case "bigint":
|
|
|
- return obj.POSITIVE_NEGTIVE_INTEGER;
|
|
|
- //return obj.POSITIVE_NEGTIVE_INTEGER.replaceAll("\\\\\\\\", "\\\\");
|
|
|
- case "decimal":
|
|
|
- return obj.POSITIVE_NEGTIVE_FLOAT;
|
|
|
- //return obj.POSITIVE_NEGTIVE_FLOAT.replaceAll("\\\\\\\\", "\\\\");
|
|
|
- case "datetime":
|
|
|
- return obj.DATE_TIME;
|
|
|
- //return obj.DATE_TIME.replaceAll("\\\\\\\\", "\\\\");
|
|
|
+ if (filedType != null) {
|
|
|
+ switch (filedType) {
|
|
|
+ case "bigint":
|
|
|
+ return POSITIVE_NEGTIVE_INTEGER;
|
|
|
+ case "decimal":
|
|
|
+ return POSITIVE_NEGTIVE_FLOAT;
|
|
|
+ case "datetime":
|
|
|
+ return DATE_TIME;
|
|
|
+ }
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
/*public static void main(String[] args) {
|
|
|
- *//*String str = "datetime";
|
|
|
- System.out.println(getRegularExpression(str));
|
|
|
- *//*
|
|
|
- String str = "2020-01-01";
|
|
|
- String pattern = "^\\d{4}-\\d{1,2}-\\d{1,2}";
|
|
|
-
|
|
|
- Pattern r = Pattern.compile(pattern);
|
|
|
+ String str = "-5465465465465546";
|
|
|
+ String pattern1 = "^-?([1-9]\\d\\*\\.\\d\\*|0\\.\\d\\*[1-9]\\d\\*|0?\\.0+|0)$";
|
|
|
+ String pattern2 = "^(-?\\d+)(\\.\\d+)?$";
|
|
|
+ String pattern3 = "^[1-2][0-9][0-9][0-9]-[0-1]{0,1}[0-9]-[0-3]{0,1}[0-9]$";
|
|
|
+ String pattern4 = "^-?((([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";
|
|
|
+ Pattern r = Pattern.compile(POSITIVE_NEGTIVE_INTEGER);
|
|
|
Matcher m = r.matcher(str);
|
|
|
System.out.println(m.matches());
|
|
|
}*/
|