how can I select date from text in java? for example if I have dates in format: 2007-01-12abcd, absc2008-01-31 and I need to have dates in format: 2007-01-12, 2008-01-31 (without text). I used matcher in my code but it is not working.
for (int i=0; i < list.size(); i++) {
Pattern compiledPattern = Pattern.compile("((?:19|20)[0-9][0-9])-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", Pattern.CASE_INSENSITIVE);
Matcher matcher = compiledPattern.matcher(list.get(i));
if (matcher.find() == true) {
new_list.add(list.get(i));
}
}