java正则提取年⽉⽇_java中正则表达式提取字符串中⽇期实现
代码
public String run(String text) {
String dateStr = placeAll("r?n", " ");
dateStr = placeAll("\s+", " ");
try {
List matches = null;
Pattern p = Patternpile("(\d{1,4}[-|\\/]\d{1,2}[-|\\/]\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})",
Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);
Matcher matcher = p.matcher(dateStr);
if (matcher.find() && upCount() >= 1) {
matches = new ArrayList();
for (int i = 1; i <= upCount(); i++) {
String temp = up(i);
matches.add(temp);
}
} else {
matches = Collections.EMPTY_LIST;
}
if (matches.size() > 0) {
return ((String) (0)).trim();
} else {
return "";
}
} catch (Exception e) {
return "";
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论