赞
踩
https://blog.51cto.com/u_13416/6411660
import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.ResolverStyle; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegTest { public static void main(String[] args) { Matcher matcher = Pattern.compile("(SCP)([0-9]{4}[0-9]{2}[0-9]{2})([0-9]{8})").matcher("fjishh哈哈哈,打卡机;SCP2023510145623587"); if (matcher.find()) { //校验日期是否合法 String format = "yyyyMMdd"; DateTimeFormatter ldt = DateTimeFormatter.ofPattern(format.replace("y", "u")).withResolverStyle(ResolverStyle.STRICT); System.out.println(matcher.group(0)); System.out.println(matcher.group(1)); System.out.println(matcher.group(2)); System.out.println(matcher.group(3)); boolean validateRes = LocalDate.parse(matcher.group(2), ldt) == null ? false : true; if (validateRes) { System.out.println("成功了"); } } } }
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。