匹配车辆牌照的前位,如”浙B”
/**
* 检查车牌前两位
* @param licensePlate
* @return true:符合;false:不符合
*/
public static boolean checkCarLicensePlate(String licensePlate) {
if (!TextUtils.isEmpty(licensePlate)) {
Pattern p = Pattern.compile("(京|沪|津|渝|黑|吉|辽|蒙|冀|新|甘|青|陕|宁|豫|鲁|晋|皖|鄂|湘|苏|川|黔|滇|桂|藏|浙|赣|粤|闽|台|琼|港|澳){1}[A-Z]{1}");
Matcher m = p.matcher(licensePlate);
if (m.matches()) {
return true;
}else {
return false;
}
}
return false;
}
匹配特殊的字符串
/**
* 过滤特殊字符
* @param str
* @return
*/
public static String replaceBlank(String str) {
String dest = "";
if (str!=null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
欢迎关注我的公众号,和我一起每天进步一点点!