java正则表达式

这是一个检测时间格式是否正确的方法,例如2020-03-22

 1 public static boolean isValidateRunningDate(String input) {
 2         //正则匹配
 3         Matcher matcher = null;
 4         boolean result = false;
 5         String regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
 6         if (input != null && !input.isEmpty()) {
 7             Pattern pattern = Pattern.compile(regex);
 8             matcher = pattern.matcher(input);
 9         }
10         if (matcher != null) {
11             result = matcher.matches();
12         }
13         return result;
14     }
原文地址:https://www.cnblogs.com/fxw-learning/p/12546803.html