java正则表达式应用
1、判断字符串是否含字母:Pattern.compile("(?i)[a-z]").matcher(phone).find()
/** * 电话号码截取 * 1、排除含有字母的电话 * 2、多个电话、只取第一个可用电话 * @param phone * @return */ public String parsePhone(String phone){ if(phone == null) return phone; if(phone.matches("^\\(?\\d{3,4}[-\\)]?\\d{7,8}$")) return phone; if(!Pattern.compile("(?i)[a-z]").matcher(phone).find()){ for (String str : phone.split("\\.+|;+|\\s+|。+|、+|`+|;+")) { return str; } } return null; }