java字符串中获取手机号码_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java字符串中获取手机号码

java字符串中获取手机号码

 2013/7/19 18:58:09  LiaoJuncai  程序员俱乐部  我要评论(0)
  • 摘要:publicclassTestRegex{publicstaticStringcheckNum(Stringnum){if(num==null||num.length()==0){return"";}Patternpattern=Pattern.compile("(?<!\\d)(?:(?:1[358]\\d{9})|(?:861[358]\\d{9}))(?!\\d)");Matchermatcher=pattern.matcher(num)
  • 标签:手机 Java 字符串
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
截取名字:史淑红
上一篇: spring jdbcTemplate 下一篇: SQL注入式攻击
发表评论
用户名: 匿名