public
class TestRegex {
public static String checkNum(String num){
??if(num == null || num.length() == 0){return "";}
??Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[358]\\d{9})|(?:861[358]\\d{9}))(?!\\d)");
??Matcher matcher = pattern.matcher(num);
??????StringBuffer bf = new StringBuffer(64);
??????while (matcher.find()) {
????????bf.append(matcher.group()).append(",");
??????}
??????int len = bf.length();
??????if (len > 0) {
????????bf.deleteCharAt(len - 1);
??????}
??????return bf.toString();
?}
?????? public static void main(String args[]) throws IOException {
???????? ?String mobileNo="史淑红<13120359225> ";
???????? ?String name=mobileNo.substring(0,mobileNo.indexOf("<"));
????????? System.out.println("截取电话为:"+
checkNum(mobileNo));
???????? ?System.out.println("截取名字:"+name);
?}
?}
?输出结果:
截取电话为:13120359225
截取名字:史淑红