java 提取字串或一段文字中的手機號碼

iteye_14978發表於2011-09-23
public static void main(String[] args) {
String text = "13522158842;托爾斯泰;test2;13000002222;8613111113313";
Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[358]\\d{9})|(?:861[358]\\d{9}))(?!\\d)");
Matcher matcher = pattern.matcher(text);
StringBuffer bf = new StringBuffer(64);
while (matcher.find()) {
bf.append(matcher.group()).append(",");
}
int len = bf.length();
if (len > 0) {
bf.deleteCharAt(len - 1);
}

System.out.println(bf.toString());
}[color=brown][/color]

相關文章