java正则匹配解析出时间
package zhengze;
import javatextParseException;
import javatextSimpleDateFormat;
import javautilregex*;
import javautilDate;
public class zhengze {
public static void main(String[] args) throws ParseException {
// String path =
// /user/sunflower/flume/msp////vortexprohadoop;
// String reg =
// ^\\d{}[][][]|[]\\d|[] [][]:[]\\d:[]\\d;
// String checkValue = /;
// String reg = ^\\d{}[]\\d[]\\d/[][]$;
//
// String reg =
// ^\\d{}[][][][] [][]:[]\\d:[]\\d$;
//
// Pattern p = pile(reg)
// Matcher m = pmatcher(checkValue)
// boolean b = mmatches()
// if(b)
// {
//
// Systemoutprintln(格式正确)
// }
// else
// {
// Systemoutprintln(格式错误)
// }
String path = /string/string/string///string/string;
// Pattern pattern = pile(\\d{}[]\\d[]\\d/[]\\d)
// Matcher matcher = patternmatcher(path)
//
// if (matcherfind()) {
// String src = matchergroup()
// Systemoutprintln(src)
// SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd/hh)
// Date date = sdfparse(src)
// Systemoutprintln(date)
//
// long t = dategetTime() + *;
//
// Systemoutprintln(t)
//
// }
Pattern pattern = pile(\\d{}[]\\d[]\\d/[]\\d)
Matcher matcher = patternmatcher(path)
Date datefile = null;
if (matcherfind()) {
String src = matchergroup()
Systemoutprintln(src)
SimpleDateFormat df = new SimpleDateFormat(yyyyMMdd/hh)
try {
datefile = dfparse(src)
} catch (ParseException e) {
// TODO Autogenerated catch block
eprintStackTrace()
}
}
long readyTime = datefilegetTime() + *;
Systemoutprintln(datefile)
Systemoutprintln(datefilegetTime())
Systemoutprintln(readyTime)
Date d = new Date(readyTime)
Systemoutprintln(dtoString())
}
}