我有一个字符串,我需要拆分并获取production_date值,所以在这个例子中我需要'2013-01-01'和'2014-01-01'。
它可能会也可能不会总是出现在本专栏中,但是对最佳方法有何建议?
where filter_2_id = 20001 and acceptable_flag is true and production_date >= '2013-01-01' AND production_date <= '2014-01-01' AND filter_2_id IN (20000, 20001) AND filter_1_id IN ( 10000 ) order by tr.test_result_id ASC
答案 0 :(得分:1)
这对你有用:
String s = "where filter_2_id = 20001 and acceptable_flag is true and production_date >= '2013-01-01' AND production_date <= '2014-01-01' AND filter_2_id IN (20000, 20001) AND filter_1_id IN ( 10000 ) order by tr.test_result_id ASC";
Pattern p = Pattern.compile("\\d{4}\\-\\d{1,2}-\\d{1,2}");
Matcher m = p.matcher(s);
while(m.find()) {
System.out.println(m.group());
}
O / P:
2013-01-01
2014-01-01