代碼如下:
@Test
public void test33() {
String phoneString = "哈哈,13888889999";
// 提取數字
// 1
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(phoneString);
String all = matcher.replaceAll("");
System.out.println("phone:" + all);
// 2
Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
}
提取張三,去除數字
復制代碼代碼如下:
@Test
public void test() {
// 提取張三 去除數字
String r_name3 = "張三 13599998888 000000";
Pattern pattern = Pattern.compile("[\\d]");
Matcher matcher = pattern.matcher(r_name3);
System.out.println(matcher.replaceAll("").trim());
}