在我们解析字符串的时候,有这么一个需求,需要提取字符中的日期,例如:"开奖日期:2021年3月28日 兑奖截止日期:2021年5月26日"
输入样例:
开奖日期:2021年3月28日 兑奖截止日期:2021年5月26日输出样例:
2021年3月28日
2021年5月26日代码实现
public void fun() {
        String text = "开奖日期:2021年3月28日 兑奖截止日期:2021年5月26日";
        Pattern p = Pattern.compile("(\\d{4})年(\\d{1,2})月(\\d{1,2})日");
        Matcher m = p.matcher(text);
        while (m.find()) {
            System.out.println(m.group(0));
        }
    }









