java regex使用正则表达式拆分字符串

时间:2015-12-10 17:35:08

标签: java regex

我有一个字符串,我需要拆分并获取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

1 个答案:

答案 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