//获取日期
public void testRegex() {
Pattern pattern = Pattern.compile("20\\d{2}(-|\\/)((0[1-9])|(1[0-2]))(-|\\/)((0[1-9])|([1-2][0-9])|(3[0-1]))");
String str = "中央政府门户网站 www.gov.cn 2008年01月22日 来源:新华社";
str = str.replace("年", "-").replace("月", "-").replace("日", "-");
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
MatchResult result = matcher.toMatchResult();
System.out.println(result.group());
}
assertTrue(true);
}
正则表达式获取日期
使用正则表达式提取日期
最新推荐文章于 2023-08-09 21:18:43 发布
本文介绍了一种使用Java正则表达式从文本中提取特定格式日期的方法,并通过一个具体示例展示了如何将日期字符串规范化并匹配。
1137

被折叠的 条评论
为什么被折叠?



