//获取日期
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);
}
正则表达式获取日期
最新推荐文章于 2024-07-10 15:25:29 发布