日期:2014-05-19 浏览次数:20972 次
public static void main(String[] args) {
String s = "00:00-08:30";
//String s = "00:00-08:30#00:00-08:30#10:00-20:00";
Pattern p = Pattern.compile("((\\d{2}:\\d{2}-\\d{2})?:\\d{2}#?)+");
Matcher m = p.matcher(s);
if(m.matches()){
System.out.println(m.group());
}
}
------解决方案--------------------
public static boolean checkStr(String str){
if(str == null || "".equals(str.trim()))
return false;
String[] arr = str.split("#");
for (String string : arr) {
if(!string.matches("\\d{2}:\\d{2}-\\d{2}:\\d{2}"))
return false;
}
return true;
}
------解决方案--------------------
^\d{2}:\d{2}-\d{2}:\d{2}(#\d{2}:\d{2}-\d{2}:\d{2})*$
------解决方案--------------------
为什么都在这里\d{2} 时间要么12小时制 要么24小时制
\d{2} 是不合法的。
^([01][\d]|2[0-4]):([0-5][\d]|60)[#]([01][\d]|2[0-4]):([0-5][\d]|60)$
------解决方案--------------------
^([01][\d]|2[0-4]):([0-5][\d]|60)-([01][\d]|2[0-4]):([0-5][\d]|60)[#]([01][\d]|2[0-4]):([0-5][\d]|60)-([01][\d]|2[0-4]):([0-5][\d]|60)$