正则校验车牌号

包含新能源车, 

public class RegEXTest {

	public static void main(String[] args) {
		String regEx = "^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$";
		// 编译正则表达式
		Pattern pattern = Pattern.compile(regEx);
		// 忽略大小写的写法
//	  Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
		String license = "渝DD12345";
		Matcher matcher = pattern.matcher(license);
		// 字符串是否与正则表达式相匹配
		boolean rs = matcher.matches();
		System.out.println(rs);
	}

}
发布了125 篇原创文章 · 获赞 27 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_39428938/article/details/90446688