import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?m)^.*(?:(?:201[8-9]|2\\d[2-9]\\d|[3-9]\\d{3})-\\d{2}-\\d{2}|2017-(?:12-\\d{2}|11-(?:0[6-9]|[12]\\d|3[01])))$";
final String string = "drwxrwxr-x - testetl hdp_test 0 2018-02-02 05:10 /raw/ADS/ClicksData/click/datetm=2017-10-15\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:35 /raw/ADS/ClicksData/click/datetm=2017-10-16\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 21:54 /raw/ADS/ClicksData/click/datetm=2017-10-17\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 23:59 /raw/ADS/ClicksData/click/datetm=2017-10-18\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 21:49 /raw/ADS/ClicksData/click/datetm=2017-10-19\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:32 /raw/ADS/ClicksData/click/datetm=2017-10-20\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 11:51 /raw/ADS/ClicksData/click/datetm=2017-10-21\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:08 /raw/ADS/ClicksData/click/datetm=2017-10-22\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 22:42 /raw/ADS/ClicksData/click/datetm=2017-10-23\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:58 /raw/ADS/ClicksData/click/datetm=2017-10-24\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 05:10 /raw/ADS/ClicksData/click/datetm=2017-10-25\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:46 /raw/ADS/ClicksData/click/datetm=2017-10-26\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:04 /raw/ADS/ClicksData/click/datetm=2017-10-27\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:46 /raw/ADS/ClicksData/click/datetm=2017-10-28\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 00:21 /raw/ADS/ClicksData/click/datetm=2017-10-29\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 05:09 /raw/ADS/ClicksData/click/datetm=2017-10-30\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 05:13 /raw/ADS/ClicksData/click/datetm=2017-10-31\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 14:34 /raw/ADS/ClicksData/click/datetm=2017-11-01\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 09:20 /raw/ADS/ClicksData/click/datetm=2017-11-02\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 14:35 /raw/ADS/ClicksData/click/datetm=2017-11-03\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:42 /raw/ADS/ClicksData/click/datetm=2017-11-04\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-02 09:18 /raw/ADS/ClicksData/click/datetm=2017-11-05\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:11 /raw/ADS/ClicksData/click/datetm=2017-11-06\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 17:56 /raw/ADS/ClicksData/click/datetm=2017-11-07\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 21:36 /raw/ADS/ClicksData/click/datetm=2017-11-08\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 16:43 /raw/ADS/ClicksData/click/datetm=2017-11-09\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-01-31 21:59 /raw/ADS/ClicksData/click/datetm=2017-11-10\n"
+ "drwxrwxr-x - testetl hdp_test 0 2018-02-01 09:23 /raw/ADS/ClicksData/click/datetm=2017-11-11\n\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html