import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestRegex {
public static void main(String[] args) { //时间正则表达式 String reg = "(.*)-(.*) (.*):(.*)"; String reg2 = "(.*)(0[1-9]|1[1-2])/(0[1-9]|[1-2]\\d|3[0-1]) ([0-2][0-9]):([0-5]\\d)(.*)"; Pattern pattern = Pattern.compile(reg2); //时间String String timeStr = "(06/06 15:50)"; Matcher matcher = pattern.matcher(timeStr); while(matcher.find()){ for(int i = 1;i<=matcher.groupCount();i++){ System.out.println(matcher.group(i)); } } }}/*
** 正则: (今天|(.*)月(.*)日 )([0-2][0-9]):([0-5]\\d) 时间:今天17:19 或 6月1日 09:53 * * 正则:(\\d{4})-(0[1-9]|1[1-2])-(0[1-9]|[1-2]\\d|3[0-1]) ([0-2][0-4]):([0-5]\\d):([0-5]\\d) 时间:2016-05-23 23:35:41 * * 正则:(0[1-9]|1[1-2])-(0[1-9]|[1-2]\\d|3[0-1]) ([0-2][0-9]):([0-5]\\d) 时间:05-04 06:33 正则:(.*)(0[1-9]|1[1-2])/(0[1-9]|[1-2]\\d|3[0-1]) ([0-2][0-9]):([0-5]\\d)(.*) 时间:(06/06 15:50) * */